Hi, I am trying to get my form to validate user input. If it is ready to complete an operation (Valid input) it affects a read-only text box with "Ready" if not "Not Ready" the values that are accepted are 1-9999, it needs to check multiple boxes aswel (The code I have at the moment just makes sure one is valid)
Here is my current code

Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
        If TextBox2.Text = ("1") And TextBox2.Text = ("1") Then
            TextBox4.Text = ("Ready!")
            MsgBox("This is not valid!", MsgBoxStyle.Exclamation, "Error")
            TextBox2.Text = ("")
        End If
    End Sub

So the ("1") needs to accept 1-9999 as valid and it needs to make sure to check both fields. I guess it doesn't do that at the moment because it's in the "TextBox2_TextChanged" sub.


7 Years
Discussion Span
Last Post by TomW

Theres a much easier way; you can get rid of the text boxes and use NumericUpDown (NUD) controls instead. The NUD is the same as a textbox but it will only allow numbers to be input. You can also set the min & max numbers allowed and whether or not you want to use a decimal point and how many places after the decimal if used.

When using the NUD through coding you will check for the Value property instead of the Text property that you would on a textbox.

TextBox2.Text = "1"

Also keep in mind that when working with a textbox, the above example is text, not actually a numeric datatype.

If you still need help with the textbox just let me know but I think the NUD is much much easier and you dont have to do as much validation or conversion back & forth between datatypes.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.