I want a msg box to display when the values in a textbox are between 1 and 17.
Should I use Integers and if statements?
And if so how?
Thanks
Printable View
I want a msg box to display when the values in a textbox are between 1 and 17.
Should I use Integers and if statements?
And if so how?
Thanks
Yes, you should. Use Convert.ToInt32 or Int32.TryParse() to see if it's a number, then compare it to 1 and 17 (If something > 1 for example).
Oh, and hello. Welcome to VBF.
Thank you for your quick reply.
However I am new to VB and need some more instruction.
This is what I have so far.
Code:Dim Soft17 As Integer
Soft17 = 1, 17
If TextBox6.Text = Soft17 Then
MsgBox("Soft 17")
End If
You can't assigned a variable two values.
Soft17 can equal 1 or 17 but not both at the same time. Try something likeIs that what you are after?vb.net Code:
Dim Soft17 As Integer = 0 'some where else If Integer.Parse(TextBox6.Text) >= 1 And Integer.Parse(TextBox6.Text) <= 17 Then MessageBox.Show("Whoop-dee-do!") Else MessageBox.Show("Sorry...please try again.") End If
That code is only safe if the text is always an integer. If you can't be certain that the item in the textbox is always an integer, then you will need to use Integer.TryParse, which is a bit more convoluted, but won't throw exceptions.
Every time I see user input and some numeric data type, I cringe when i see something other than .TryParse. I don't understand why someone would answer any other way.
so would he have to rewwtir that as
dim soft17 as integer.tryparse??
if not where would i have to input that '.tryparse' linee plz?
vb Code:
Dim Soft17 As Integer If Integer.TryParse(TextBox6.Text, Soft17) Then If Soft17 >= 1 And Soft17 <= 17 Then MsgBox("between 1 and 17") Else MsgBox("out of range number") End If Else MsgBox("Not a number") End If
The post I had refered too was deleted, rendering my comment a random critique of Mendhak.