If a value is between.. End If

Lanc1988

Well-known member
Joined
Nov 27, 2003
Messages
508
In my button code I want to add an "IF" statement so that If the label is between the numbers 1 through 5 it will show text in another label. The problem is, i cant seem to figure out how to do the 1 through 5 part.


I have tried:

IF TextBox1.Text (1:5) Then
Label1.Text = "You are between 1 and 5"
End IF
 
First you need to convert the Text, which is a string, into a number
that can be compared numerically. Then use a combination of the
greater-than (>) and less-than (<) operators to check for
betweenness.

Code:
Dim value As Integer
value = Convert.ToInt32(TextBox1.Text)  Convert to Integer
If value > 1 And value < 5 Then
  Label1.Text = "You are between 1 and 5"
End if

If you want it to be between 1 and 5 inclusive, then use the
>= and <= operators, instead.
 
Back
Top