|
-
Apr 1st, 2009, 05:10 AM
#1
Thread Starter
New Member
[RESOLVED] Integer
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
-
Apr 1st, 2009, 05:17 AM
#2
Re: Integer
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.
-
Apr 1st, 2009, 05:57 AM
#3
Thread Starter
New Member
Re: Integer
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
-
Apr 1st, 2009, 06:01 AM
#4
Re: Integer
You can't assigned a variable two values.
Soft17 can equal 1 or 17 but not both at the same time. Try something like
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
Is that what you are after?
-
Apr 1st, 2009, 09:15 AM
#5
Re: Integer
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.
My usual boring signature: Nothing
 
-
Apr 1st, 2009, 12:33 PM
#6
Re: Integer
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.
-
Apr 1st, 2009, 02:20 PM
#7
Junior Member
Re: Integer
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?
-
Apr 1st, 2009, 02:29 PM
#8
Re: Integer
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
-
Apr 1st, 2009, 03:51 PM
#9
Re: Integer
The post I had refered too was deleted, rendering my comment a random critique of Mendhak.
My usual boring signature: Nothing
 
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|