February 9th, 2013, 05:45 PM
Validation Rule for TextBox
This is my first post here so Hi everyone.
I am new to VB and I am creating program that calculate the area of the room and calculate the price of the paint etc. One of the restriction is that the height of the room must be between 2 and 6 and the length must be between 1 and 25. I have two text boxes, one for hight and one for length. I need to add validation rule for both of them. I tried few codes but none of the worked for me. I was still able to calculate any number.
February 9th, 2013, 10:48 PM
I forgot to add that I am using Windows Forms Application (I am not sure if it does matter or not).
February 25th, 2013, 12:54 PM
Validation rules are generally set at the table level of a database design. However, you are using a smart form that will only use the variables for a temporary time, the time needed to perform your calculation. On the forms properties section for each of the controls, be sure that you can enter integer values. Look for a validation field to enter your min and max values. DO NOT use double quotes when assigning the int values. Should look something like this:
Validation Rule: >=2 AND <=6
Between 2 AND 6.
Too many different ways to handle this validation. OPEN AN
First of all the easiest way is change the textbox to combobox and add item what you want only.
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
If Val(TextBox1.Text) > 6 Or Val(TextBox1.Text) < 2 Then
MsgBox("You can entered between 2 to 6.", MsgBoxStyle.Information, My.Application.Info.ProductName)
TextBox1.Text = ""