Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 4 - Operators
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

Operators
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2007-09-06

    Table of Contents:
  • Operators
  • Concatenation Operators
  • Logical and Bitwise Operators Continued
  • Assignment Operators

  • 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

    Ajax Application Generator Generate database 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!

    Operators - Assignment Operators
    (Page 4 of 4 )

    Along with the standard assignment operator (=), many other operators can be turned into assignment operators by simply appending an equals sign to the right of the operator. These converted operators all have the same form:

      expression1 <operator>= expression2

    where <operator>  is the operator being promoted to an assignment operator. This form is equivalent to:

      expression1 = expression1 <operator> expression2

    To illustrate, consider the addition assignment operator. The expression:

      x += 1

    is equivalent to:

      x = x + 1

    which simply adds 1 to the value of x . Similarly, the expression:

      s &= "end"

    is equivalent to:

      s = s & "end"

    which concatenates the string "end" to the end of the string s.

    All of these "shortcut" assignment operators were introduced with Visual Basic .NET 2002.

    = (Assignment)

    The assignment operator assigns the value or reference of the expression on the right of the assignment operator to the variable on the left. For example, the following assigns y plus an additional value of 5 to x .

      x = y + 5

    The assignment operator alone is used to assign both values and references; in previous versions of VB, the Set statement had to be used along with the assignment operator to assign an object reference. The Set keyword is no longer used in this context. Also, the previously optional Let keyword is no longer part of the Visual Basic language.

    +=

    The addition assignment operator. As an example:

      totalValue += 1

    adds 1 to the value of totalValue and assigns the result to totalValue.

    -=

    The subtraction assignment operator. As an example:

      totalValue -= 1

    subtracts 1 from the value of totalValue and assigns the result to totalValue.

    *=

    The multiplication assignment operator. As an example:

      totalValue *= 3

    multiplies the value of totalValue by 3 and assigns the result to totalValue.

    /=

    The division assignment operator. As an example:

      totalValue /= 2

    divides the value of totalValue by 2 and assigns the result to totalValue. If the value to the right of the division assignment operator equates to 0, an error occurs.

    \=

    The integer division assignment operator. As an example:

      totalValue \= 2

    divides the value of totalValue by 2, discards any fractional part, and assigns the result to totalValue. If the value to the right of the integer division assignment operator equates to 0, an error occurs.

    ^=

    The exponentiation assignment operator. As an example:

      totalValue ^= 2

    squares the value of totalValue and assigns the result to totalValue.

    &=

    The concatenation assignment operator. As an example:

      storyText &= "The End"

    appends a literal text string to the end of storyTexts existing content and assigns this new concatenated string to storyText.

    <<=

    New in 2003. The shift left assignment operator. As an example:

      dataMask <<= 2

    shifts the bits of dataMask left two positions and assigns the new value back to dataMask.

    >>=

    New in 2003. The shift right assignment operator. As an example:

      dataMask >>= 2

    shifts the bits of dataMask right two positions and assigns the new value back to dataMask.

    Unlike the comparison operators, in which the order of symbols is reversible (that is, >= is the same as =>), the order of the "shortcut" assignment operator symbols is not reversible. For example, while:

      x -= 1

    decrements x by 1, the expression :

      x =- 1

    assigns a value of 1 to the variable x . That is, it really looks like this:

      x = -1

    Please check back next week for the conclusion to this article.


    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 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...

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




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