Group,

I see there are multiple "validation" type events to choose from in the "Declarations" drop-down box. I want to understand these choices better to see if one would work for what I want to do.

I've got several textboxes that need to have either a number entered into them or simply left blank. So I'd like to check during the time the user is inputing to see if what they have entered is correct, and if it's not, send them a message that they need to correct it. As an example:

If IsNumeric(txbSpecialPrice.Text) = False Or txbSpecialPrice.Text = "0" Then
            MessageBox.Show("This field must be blank or a valid special price greater than 0...", "Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            txbSpecialPrice.Focus()

So this prompted me to wonder if the event of "Validating" or something like it would be the best thing to use:

Private Sub txbCustNoType_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles txbCustNoType.Validating

If not this, what would the better to check during the run-time? I recognize that the user may not always tab or enter through each field, he/she may opt to use the mouse and go directly a specific box they want to choose. Therefore I think it would be wise to ensure each textbox has the correct kind of information in it.

What are your thoughts on this? Remember, I'm a newbie programmer. If you comment, please explain!

Thanks for your help.

Don

Ok.... It seems I'm on the right track. Correct me if I'm wrong here, but it appears that I could do the following:

Private Sub textBox1_Validating(ByVal sender As Object, _
   ByVal e As System.ComponentModel.CancelEventArgs) Handles textBox1.Validating

   'check to see if the textbox has is correct or not

    If textbox1.Text.Length > 0 Then
        If IsNumeric(textbox.Text) = False
        MessageBox.Show("This field must be blank or a valid special price greater than 0...",
        "Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        textBox1.Select(0, textBox1.Text.Length)
    Else
        Dim txbx1 as Integer = Convert.ToInt32(texBox1.Text)
    End If
    If textbox1.Text.Length = 0 Then
        Dim txbx1 As String = "NULL"
    End If

Assuming this is correct, when would this event run? As soon as any change in the textbox happens?

The info says that I can't "textBox1.Focus" as it could shut the whole thing down. But does textBox1.Select(0, textBox1.Text.Length) essentially do the same thing? I hope so.

Thanks for the direction. I google this stuff and, for some reason, I never find the links you send.

Don

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.