user2170523
user2170523

Reputation: 19

Textbox Value Range VB.NET

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

Answers (4)

George
George

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

Rajaprabhu Aravindasamy
Rajaprabhu Aravindasamy

Reputation: 67207

This may be the time for you to know about < and > operators.

If (value > 99 And value < 201) Then 

Upvotes: 0

mr_plum
mr_plum

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

Reed Copsey
Reed Copsey

Reputation: 564403

You need to check individually:

Dim value = val(textbox1.text)
If (value >= 100 And value <= 200) Then 
    ' ....

Upvotes: 1

Related Questions