How to do greater than X and less than Y in VB?
16,109
Solution 1
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
Solution 2
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.
Author by
Henry Boldizsar
Updated on June 14, 2022Comments
-
Henry Boldizsar almost 2 years
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.