+ Reply to Thread
Results 1 to 2 of 2

Thread: VB.NET from beginner to advanced programmer Part 6 - Relational Operators

  1. #1
    Join Date
    Apr 2009
    Location
    Uppsala, Sweden
    Posts
    9,547
    Blog Entries
    5
    Rep Power
    98

    VB.NET from beginner to advanced programmer Part 6 - Relational Operators

    Welcome to the VB.NET tutorial series: "VB.NET from beginner to advanced programmer" which will take you from the very beginning to be a good programmer. VB.NET is a good first language for new programmers so this 21 part long series is written for completely beginners but it will also works perfectly fine if you already know another programming language.


    VB.NET from beginner to advanced programmer
    1. Introduction and Installation
    2. Objects and Events
    3. Variables
    4. The basic data types
    5. Logical Operators
    6. Relational Operators
    7. If statements Then
    8. Arithmetical Operators
    9. Loops Part 1
    10. Arrays
    11. Loops Part 2
    12. Try Catch statements
    13. Subs and Functions
    14. Difference between Scopes
    15. Select Statements
    16. Multidimensional arrays
    17. Structures
    18. Classes
    19. Enumerations
    20. Advanced Comments
    21. 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:

    Code:
    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:



    Code:
    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:


    Code:
    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:


    Code:
    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.
    Last edited by Vswe; 03-21-2010 at 03:28 PM.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Jordan Guest

    Re: VB.NET from beginner to advanced programmer Part 6 - Relational Operators

    Nicely done, +rep!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 3
    Last Post: 11-02-2009, 05:40 PM
  2. Replies: 3
    Last Post: 11-02-2009, 05:20 PM
  3. Replies: 1
    Last Post: 11-02-2009, 06:05 AM
  4. Replies: 1
    Last Post: 11-02-2009, 05:46 AM
  5. Replies: 1
    Last Post: 11-02-2009, 05:43 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts