Reputation: 19
How can set a range for the numbers in VB.NET . e.g
If val(textbox1.text = 100 to 200) then
// messagebox.show("The number is between 100 and 200")
end if
What should I put instead of "to" to get it working ?
Upvotes: 2
Views: 5143
Reputation: 2213
For something short like this, a simple IF would look better. But if you have multiple checks for multiple ranges, a Select Case
works better:
Select Case Val(textbox1.Text)
Case 100 To 200
' Number between 100 and 200 inclusive
Case Else
' anything else
End Select
Upvotes: 0
Reputation: 67207
This may be the time for you to know about <
and >
operators.
If (value > 99 And value < 201) Then
Upvotes: 0
Reputation: 2437
Reed Copsey is correct, but I always favor short-circuiting the condition with AndAlso
If (value >= 100 AndAlso value <= 200) Then
Upvotes: 1
Reputation: 564403
You need to check individually:
Dim value = val(textbox1.text)
If (value >= 100 And value <= 200) Then
' ....
Upvotes: 1