Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 4 - Operators
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  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
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 / 2
    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
     
     
    ADVERTISEMENT


    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

    - User-defined Functions using Visual Basic Ap...
    - Understanding Object Binding in VBA
    - Mastering the Message Box
    - Testing a Windows Forms Application
    - Using Visual Basic.NET Features to Code a Wi...
    - Correcting Code in a Windows Forms Applicati...
    - Write Readable Code and Comments for Windows...
    - How to Code and Test a Windows Forms Applica...
    - Adding Features to a Windows Forms Applicati...
    - How to Design a Windows Forms Application
    - LINQ to XML Programming Using Visual Basic.N...
    - Understanding Delegates using Visual Basic.N...
    - Create a Sudoku Puzzle Generator using VB.NET
    - Entity Creation and Messaging in a VB.NET Te...
    - Movement and Player Statistics in a VB.NET T...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek