Something went wrong. Try again.
A collection of projects I've done for Berks Career and Technology Center Information Technology Programming
Something went wrong. Try again.
4.0 kB · 211 lines
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212Option Strict On
Public Enum TextType As Integer
Text Money Decimal_Point Whole
End Enum
Public Class TextField
'Properties
Private Property clrNormalColor As Color Private Property blnIsValid As Boolean Private Property ttyType As TextType Private Property intMinChars As Integer = -1 Private Property intMaxChars As Integer = -1 Private Property dblMinNumber As Double Private Property dblMaxNumber As Double
'Get Functions
Public Function GetValue() As String
Return txtInput.Text
End Function
Public Function IsValid() As Boolean
Return blnIsValid
End Function
'Set Functions
Public Sub SetName(strNewName As String)
grpField.Text = strNewName
End Sub
Public Sub SetType(type As TextType)
ttyType = type
End Sub
Public Sub SetCharMinMax(minChars As Integer, maxChars As Integer)
intMinChars = minChars intMaxChars = maxChars
End Sub
Public Sub SetNumberMinMax(minNumber As Double, maxNumber As Double)
dblMinNumber = minNumber dblMaxNumber = maxNumber
End Sub
'Reset Functions
Private Sub Forgive()
lblErrorText.Visible = False txtInput.BackColor = clrNormalColor ForeColor = DefaultForeColor txtInput.BackColor = Color.White
End Sub
Public Sub Clear()
Forgive() txtInput.Clear()
End Sub
Public Sub Empty()
txtInput.Clear()
End Sub
'Events
Private Sub Me_Layout() Handles Me.Layout
With txtInput
.Size = New Size(Size.Width - 50, 20) .Location = New Point(Size.Width \ 2 - (txtInput.Size.Width \ 2), Size.Height \ 5 + 10)
End With
With lblErrorText
.AutoSize = False .Size = New Size(Size.Width - 20, 20) .Location = New Point(10, txtInput.Size.Height + (Size.Height - txtInput.Size.Height) \ 2) .Text = "Error Text" .TextAlign = ContentAlignment.MiddleCenter .ForeColor = Color.Red .BackColor = BackColor .Visible = False
End With
With grpField
.Size = Me.Size
End With
End Sub
'Validation
Private Sub ValidateForText()
Dim strValue As String = GetValue()
If Validators.IsntEmpty(strValue) Then
If Validators.InCharRange(strValue, intMinChars, intMaxChars) Then
blnIsValid = True
Else
InvalidInput("Too Short/Long!")
End If Else
InvalidInput("Can't Be Empty!")
End If End Sub
Private Sub InvalidInput(strMessage As String)
blnIsValid = False lblErrorText.Visible = True lblErrorText.Text = strMessage ForeColor = Color.Red txtInput.BackColor = Color.LightPink
End Sub
Private Sub ValidateForNumber(Optional blnForceWhole As Boolean = False)
Dim strValue As String = GetValue() ValidateForText()
If blnIsValid Then
Dim strReason As String = ""
If Validators.CanConvert(ttyType, strValue, strReason, blnForceWhole) Then
If Validators.InNumberRange(strValue, ttyType, dblMinNumber, dblMaxNumber) Then
blnIsValid = True
Else
InvalidInput("Not In Range!")
End If
Else
InvalidInput(strReason & "!")
End If
End If
End Sub
Public Overloads Sub Validate() Handles Me.Leave
If ttyType = TextType.Text Then
ValidateForNumber()
ElseIf ttyType = TextType.Whole Then
ValidateForNumber(True)
Else
ValidateForNumber(False)
End If
If blnIsValid Then
Forgive()
End If
End Sub
End Class