Henry Boldizsar
Henry Boldizsar

Reputation: 489

How to do greater than X and less than Y in VB?

Here is what I have tried... which is completely wrong I assume, as it did not work.

If ProgressBar1.Value > 5 < 20 Then
    Label8.Text = "Hello"
End If

All help is greatly appreciated! Thank you.

Upvotes: 2

Views: 17301

Answers (2)

Rob P.
Rob P.

Reputation: 15071

If ProgressBar1.Value > 5 AndAlso ProgressBar1.Value < 20 Then
    Label8.Text = "Hello"
End If

Is one way.

AndAlso means that the condition will 'short circuit' if the first value evaluates to false. So if ProgressBar1.Value is not > 5 - it won't bother checking the rest of the condition.

You could also write it using And

If ProgressBar1.Value > 5 And ProgressBar1.Value < 20 Then
    Label8.Text = "Hello"
End If

and it would evaluate both conditions. In this particular case, it won't make much difference, but I generally prefer AndAlso/OrElse over And/Or

Upvotes: 6

goldemerald
goldemerald

Reputation: 39

You have to do an and statement using the "And" line. It should look something like this

If ProgressBar1.Value > 5 And ProgressBar1.Value < 20 Then
    Label8.Text = "Hello"
End If

Additionally you can use the "or" statement if you just want one of them to be true.

Upvotes: 2

Related Questions