Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'Check for correct input.
- Public Sub Validate_Realtime(txtObj As Object, lblObj As Object, countText As Boolean, numCheck As Boolean, txtEvent As String)
- 'Output Sub paramaters as message box. For debugging only.
- 'Dim outputParamTest1 As String = "Text Object = " + Convert.ToString(txtObj.Name) + " | Label Object =" + Convert.ToString(lblObj.Name) + " | Count text? = " + Convert.ToString(countText) + " | Check for numeric? = " + Convert.ToString(numCheck) + " | Text Event = " + txtEvent
- 'MessageBox.Show(outputParamTest1)
- If txtEvent = "Enter" Or txtEvent = "Changed" Then
- If numCheck = True Then
- 'Check for numeric input.
- If Not IsNumeric(txtObj.Text) And txtObj.Text.Length > 0 Then
- ErrorAppPIN.SetError(txtObj, "Numeric input only!")
- Else
- ErrorAppPIN.SetError(txtObj, "")
- End If
- 'Check for correct input.
- If IsNumeric(txtObj.Text) And txtObj.Text.Length = txtObj.MaxLength Then
- SuccessAppPIN.SetError(txtObj, "Acceptable!")
- Else
- SuccessAppPIN.SetError(txtObj, "")
- End If
- Else
- 'Check for correct input.
- If txtObj.Text.Length = txtObj.MaxLength Then
- SuccessAppPIN.SetError(txtObj, "Acceptable!")
- Else
- SuccessAppPIN.SetError(txtObj, "")
- End If
- End If
- If countText = True Then
- 'Show count of text length and max length.
- 'Text length.
- Dim txtObjCount As String = txtObj.text.length
- 'Max length.
- Dim txtObjMax As String = txtObj.maxlength
- 'String for label.
- Dim lblObjString As String = "[ " + txtObjCount + " / " + txtObjMax + " ]"
- lblObj.text = lblObjString
- 'Display label.
- lblObj.Visible = True
- End If
- ElseIf txtEvent = "Leave" Then
- 'Hide label.
- lblObj.Visible = False
- If txtObj.Text.Length < txtObj.MaxLength And txtObj.Text.Length > 0 Then
- ErrorAppPIN.SetError(txtObj, "Not enough digits!")
- ElseIf txtObj.Text.Length = 0 Then
- ErrorAppPIN.SetError(txtObj, "Input required!")
- Else
- ErrorAppPIN.SetError(txtObj, "")
- End If
- End If
- End Sub
- 'When a text box is entered (i.e. tabbed/clicked into).
- Private Sub TextBox_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtAppNum.Enter, txtPIN.Enter
- Dim txtevent As String = "Enter"
- 'Determine active text box.
- Dim txtactive As TextBox
- txtactive = CType(sender, TextBox)
- If (txtactive Is txtAppNum) Then
- Validate_Realtime(txtAppNum, lblCountAppNum, True, True, txtevent)
- ElseIf (txtactive Is txtPIN) Then
- Validate_Realtime(txtPIN, lblCountPIN, True, True, txtevent)
- End If
- End Sub
- 'When a text box's text is changed.
- Private Sub textbox_textchanged(sender As Object, e As EventArgs) Handles txtAppNum.TextChanged, txtPIN.TextChanged
- Dim txtevent As String = "changed"
- 'Determine active text box.
- Dim txtactive As TextBox
- txtactive = CType(sender, TextBox)
- If (txtactive Is txtAppNum) Then
- Validate_Realtime(txtAppNum, lblCountAppNum, True, True, txtevent)
- ElseIf (txtactive Is txtPIN) Then
- Validate_Realtime(txtPIN, lblCountPIN, True, True, txtevent)
- End If
- End Sub
- 'When Application # text box left (i.e. tabbed/clicked out of).
- Private Sub TxtAppNum_Leave(sender As Object, e As EventArgs) Handles txtAppNum.Leave, txtPIN.Leave
- Dim txtEvent As String = "Leave"
- 'Determine active text box.
- Dim txtActive As TextBox
- txtActive = CType(sender, TextBox)
- If (txtActive Is txtAppNum) Then
- Validate_Realtime(txtAppNum, lblCountAppNum, True, True, txtEvent)
- ElseIf (txtActive Is txtPIN) Then
- Validate_Realtime(txtPIN, lblCountPIN, True, True, txtEvent)
- End If
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment