Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • *Experts*
Posted

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.

 

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.

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...