Results 1 to 6 of 6

Thread: [RESOLVED] Validation on multiple fields?

Threaded View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2006
    Posts
    26

    [RESOLVED] Validation on multiple fields?

    Im trying to validate all the fields before I enable the calcButton. The issue I'm having is that the errorMessage doesn't clear once i enter a correct value. Hence the calcButton is disabled. How can I clear the ErrorProvider once the validation is good?

    This code is probably not the write way to do it. Any advice on a better way to code it would be greatly appreciated, and if you have some sample coding that would be icing on the cake.

    Thanks again.

    VB Code:
    1. Private Sub SetFormErrorState()
    2.         Dim errorMessage As String = Nothing
    3.         'Checking CC# for numeric
    4.         If Not Me.ValidateTextBox(Me.phoneTextBox.Text) Then
    5.             'The user has not entered the required value.
    6.             errorMessage = "Entry Required"
    7.             'Checking phone for numeric
    8.             Me.ErrorProvider.SetError(Me.phoneTextBox, errorMessage)
    9.  
    10.         ElseIf Me.ccTextBox.Enabled AndAlso Not Me.ValidateTextBox(Me.ccTextBox.Text) Then
    11.             'The user has not entered the required value.
    12.             errorMessage = "Entry Required"
    13.             Me.ErrorProvider.SetError(Me.ccTextBox, errorMessage)
    14.  
    15.         ElseIf Not Me.ValidateTextBox(Me.startMiTextBox.Text) Then
    16.             'The user has not entered the required value.
    17.             errorMessage = "Entry Required"
    18.             Me.ErrorProvider.SetError(Me.startMiTextBox, errorMessage)
    19.  
    20.         ElseIf Not Me.ValidateTextBox(Me.endMiTextBox.Text) Then
    21.             'The user has not entered the required value.
    22.             errorMessage = "Entry Required"
    23.             Me.ErrorProvider.SetError(Me.endMiTextBox, errorMessage)
    24.  
    25.         ElseIf Not Me.ValidateTextBox(Me.daysRentedTextBox.Text) Then
    26.             'The user has not entered the required value.
    27.             errorMessage = "Entry Required"
    28.             Me.ErrorProvider.SetError(Me.daysRentedTextBox, errorMessage)
    29.         Else
    30.             Me.ErrorProvider.Clear()
    31.         End If
    32.  
    33.         'Enable the OK button if and only if there are no errors.
    34.         Me.calculateButton.Enabled = (errorMessage Is Nothing)
    35.     End Sub
    36.  
    37.     Private Function ValidateTextBox(ByVal varTextBoxString As String) As Boolean
    38.         If varTextBoxString = "" Then
    39.             Return False
    40.         Else
    41.             Return True
    42.         End If
    43.         'Return True if the TextBox contains any value, otherwise return False.
    44.     End Function
    Last edited by mrman99; Sep 19th, 2006 at 10:30 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width