VB.NET from beginner to advanced programmer
- Introduction and Installation
- Objects and Events
- Variables
- The basic data types
- Logical Operators
- Relational Operators
- If statements Then
- Arithmetical Operators
- Loops Part 1
- Arrays
- Loops Part 2
- Try Catch statements
- Subs and Functions
- Difference between Scopes
- Select Statements
- Multidimensional arrays
- Structures
- Classes
- Enumerations
- Advanced Comments
- Compiling Directives
Next comes the relational operator which will take two values and compare them, it will then return a boolean value depending on the relation between the values. There's a total of 6 relational operators which you can use in VB.NET, they are: Equals to, Not equals to, Greater then, Less then, Greater then or equals to and less then or equals to.
Equals to:
Writes "="
This relational operator checks if the two values are the same, if they are, it will return True. Here's some examples:
MessageBox.Show(False = True) MessageBox.Show(7 = 7) MessageBox.Show(8 = 8.000)These three messageboxes will show False, True and True. False and True is not equals to each other so that one returns False. In the second one both the values are 7 so that one will return True. In the last one the both values are not exactly the same values but the values have the same size so that one will also return True.
Remember that you also use the equals sign for setting values of variables.
Not equals to:
Writes "<>"
This is the opposite of the Equals to operator. The Not equals to operator will return true if the values it compares are not the same. If we're using the Not logical operator together with the equals to relational operator we can create a Not equals to operator in another way. Anyway, here's a few example of the normal Not equals to operator:
MessageBox.Show(1 <> 3)
MessageBox.Show(-5 <> -5)
MessageBox.Show("text" <> "another text")
1 and 3 are not the same so therefor the first messagebox will show "True". The second one's values is the same so that one will return False. In the last one we use two string instead, the both strings are not the same so the third messagebox will show "True".
Greater then and Less then:
Writes ">" and "<"
The Greater then and Less then operators will compare the size of the two values. If you use them on non-numeric values you get strange results so try to avoid using them together with non-numeric values. Here comes some example on how to use them with numeric values:
MessageBox.Show(25 > 3) MessageBox.Show(5 < 42) MessageBox.Show(12 > 12)
Since 25 is greater then 3 the first will return True. The second one is also True since 5 is less then 42. The last one is a little bit trickier, but 12 is not greater then 12, therefor the last one will return False.
Greater then or equals to and Less then or equals to:
Writes ">=" and "<="
The Greater then or equals to is the same as Greater then and Less then or equals to is the same as Less then, both with one exception. If the two values are the same Greater then or equals to and Less then or equals to will return True which is not the case for Greater then and Less then which will return false. Here comes some example, these example uses the same values as in the last subject about Greater then and Less then:
MessageBox.Show(25 >= 3) MessageBox.Show(5 <= 42) MessageBox.Show(12 >= 12)
In the first and second example we will get the same result as before. But in the last example we will get a difference. 12 is not greater then 12 but 12 is equals to 12, therefor Greater then or equals to will return True here were Greater then returned False with the same values.
In the next part about If statements we will use both Logical Operators and Relational operators. See you then.
Edited by Vswe, 21 March 2010 - 02:28 PM.


Sign In
Create Account


Back to top









