Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 4 - Types of Operators in Visual Basic
Iron Speed
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Download TestComplete 
Windows Web Hosting
 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
VISUAL BASIC.NET

Types of Operators in Visual Basic
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 5
    2007-09-13

    Table of Contents:
  • Types of Operators in Visual Basic
  • The Like Operator
  • Operator Overloading
  • Operator Precedence

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    Iron Speed
     
    ADVERTISEMENT

    Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    Types of Operators in Visual Basic - Operator Precedence
    (Page 4 of 4 )

    If you include more than one operator in a single line of code, you need to know the order in which VB will evaluate them. Otherwise, the results may be completely different from what you intended. For instance, the following statement:

      x = 5 + 3 * 7

    could be interpreted as:

      x = (5 + 3) * 7 ' --> 56

    or as:

      x = 5 + (3 * 7) ' --> 26

    The rule that defines the order in which a language processes operators is known as the order of precedence. If the order of precedence results in operations being evaluated in an order other than the intended one, you can explicitly override the order of precedence through the use of parentheses. Indeed, complex (or even relatively simple) expressions should include parentheses to avoid any compiler misinterpretation or human confusion. (By the way, the example, once parentheses are removed, evaluates to 26.)

    When multiple operators appear at the same level of evaluation (that is, they are not subgrouped with parentheses), they are processed in a specific order of precedence. In some instances, multiple operators appear at the same level of precedence (as are * and /). They are treated as equals as far as precedence is concerned. The following list indicates the order of precedence in evaluation, from first to last.

    1. Exponentiation (^).
    2. Negation (-).
    3. Multiplication and division (*, /).
    4. Integer division (\).
    5. Modulo operator (Mod).
    6. Addition/concatenation and subtraction (+, -).
    7. String concatenation (&).
    8. New in 2003. Arithmetic bit shift (<<, >>).
    9. Comparison and object operators (=, <>, <,  <=, >, >=, Like, Is, IsNot, TypeOf); the = operator in this list is the Equal To comparison operator, not the assignment operator. New in 2005. The IsNot operator is new in the 2005 release of VB.
    10. Logical and bitwise negation (Not).
    11. Logical and bitwise conjunction (And, AndAlso). New in 2005. The AndAlso operator is new in the 2005 release of VB.
    12. Logical and bitwise disjunction (Or, OrElse, Xor ). New in 2005. The OrElse operator is new in the 2005 release of VB.

    Since the AddressOf and GetType operators are implemented like functions, they fall outside of the order of precedence rules for operators.

    If multiple operators of the same order of precedence appear at the same level of evaluation, they are processed from left to right.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · This article is an excerpt from the book "Visual Basic 2005 in a Nutshell, Third...
     

    Buy this book now. This article is excerpted from chapter five of the book Visual Basic 2005 in a Nutshell, Third Edition, written by Tim Patrick, Steven Roman, Ph.D., Ron Petrusha and Paul Lomax (O'Reilly; ISBN: 059610152X). Check it out today at your favorite bookstore. Buy this book now.

    VISUAL BASIC.NET ARTICLES

    - Types of Operators in Visual Basic
    - Operators
    - Understanding Custom Events using Visual Bas...
    - Polymorphism using Abstract Classes in Visua...
    - Shadowing using Shadows in Visual Basic.NET ...
    - Overloading and Overriding in Visual Basic.N...
    - More on Controlling Windows Fax Services Usi...
    - Programmatically Controlling Windows Fax Ser...
    - Focusing on Forms and Menus in Visual Basic
    - Manipulating Forms with the Windows Forms Li...
    - Basics of the Windows Forms Library
    - Forms, Controls, and Other Useful Objects
    - Implementing OOP to Develop Database Oriente...
    - Using Themes and Skins for Personalization w...
    - A Deeper Look at Personalization using Visua...




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway