need help declaring and calling

Dar

New member
Joined
Oct 10, 2004
Messages
2
Programming Experience
Beginner
I'm trying to use validating event handler to check if the user is inputting the correct data but

when i use the

ErrorProvider1

or

IsNumberInRange

I'm not sure how to declare or Call them

can anyone help here is the code

problem 1
Private Sub txtNumber_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtNumber.Validating

'See if the text is 10 digits

If Not (txtNumber.Text Like "###-###-####") Then

'The phone number is not valid

'Cancel the event moving off of the control

e.Cancel = True

'select the offending text

txtNumber.Select(0, txtNumber.Text.Length)

'Give the ErrorProvider the error message to display

ErrorProvider1.SetError(txtNumber, "Invalid Phone Number" & "Format")

End If

Problem 2

Dim IsStringInRange As Text' what do i put here to make this work?

Private Sub txtFirst_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtFirst.Validating
txtFirst.Text = StrConv(txtFirst.Text, VbStrConv.ProperCase)

If IsStringInRange(txtFirst.Text, 1, 20) Then

lblInvalidFirstName.Visible = False

Else

lblInvalidFirstName.Visible = True

End If

End Sub

 

Paszt

Staff member
Joined
Jun 3, 2004
Messages
1,500
Location
Raleigh, NC - USA
Programming Experience
Beginner
I would do this for the errorProvider:

VB.NET:
Private Sub txtNumber_Validating(ByVal sender As Object, _
  ByVal e As System.ComponentModel.CancelEventArgs) _
  Handles txtNumber.Validating
    If Not (txtNumber.Text Like "###-###-####") Then
        e.Cancel = True
        txtNumber.Select(0, txtNumber.Text.Length)
        ErrorProvider1.SetError(txtNumber, "Invalid Phone Number" & "Format")
    Else
        ErrorProvider1.SetError(txtNumber, "")
    End If
End Sub
Notice though, that the line: ErrorProvider1.SetError(txtNumber, "Invalid Phone Number" & "Format") will set the error text to "Invalid Phone NumberFormat".

Regarding Problem2, what is it you're trying to accomplish?

More than likely, you'll want to create a function called IsStringInRange. It would be structured similar to this:

VB.NET:
Function IsStringInRange(ByVal str as String, ByVal i as integer, _
  ByVal j As Integer) as Boolean
    'Code to evaluate if str is in Range
End Function
 

Dar

New member
Joined
Oct 10, 2004
Messages
2
Programming Experience
Beginner
Thanks a heap will give it a go.
 
Top Bottom