|
Free
computer Tutorials
|
![]() |
home |
Stay
at Home and Learn
|
||||||||
Conditional Operators |
|||||||||
|
VB NET - Operators
The Conditional Operators allow you to refine what you are testing for. Instead of saying "If X is equal to Y", you can specify whether it's greater than, less than, and a whole lot more. Examine the list of Operators: |
||||||||
| Operator | Meaning | ||||||||
| > |
This symbol means Is Greater Than and is used like this: If number > 10 Then
|
||||||||
| < |
This symbol means Is Less Than and is used like this: If number <10 Then
|
||||||||
| >= |
These symbols mean Is Greater Than or Equal to, and are used like this: If number >= 10 Then
|
||||||||
| <= |
These symbols mean Is Less Than or Equal to, and are used like this: If number <= 10 Then
|
||||||||
| And |
You can combine the logical operators with the word And. Like this: If number > 5 And number < 15 Then
|
||||||||
| Or |
You can combine the logical operators with the word Or. Like this: If number > 5 Or number < 15 Then
|
||||||||
| <> |
These symbols mean Is Not Equal to, and are used like this: If number1 <> number2 Then |
||||||||
|
A word about And and Or. Notice the format with And and Or. The variable is repeated twice If VariableName = 7 Or VariableName = 10 Then MsgBox "7 or 10 spotted" If you just put something like this If VariableName > 7 Or < 10 Then MsgBox "7 or 10 spotted" then Visual Basic will give you an error message. What you have to say is If [test the variable for this value] And [test the variable for that value] Then Your If statement can contain an Else part, too. The format is this: If [conditional logic
here] Then But don't worry if all that hasn't sunk in - you'll get used to the Conditional Operators as you go along. In the next part, there's two little programmes for you to write. They will test the skills you have acquired so far.
Click here to move on to the Section Three Exercises --> Click here to jump to Loops in Visual Basic .NET--> |
|||||||||