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


    (Page 1 of 4 )

    Operators are the basic data manipulation tools of any programming language. All data ultimately breaks down into single bits of 0 and 1. And the whole reason a computer exists is to manipulate those single bits of data with basic operators. This article discusses the basic operators available in Visual Basic, and how they interact with data. 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). Copyright © 2006 O'Reilly Media, Inc. All rights reserved. Used with permission from the publisher. Available from booksellers or direct from O'Reilly Media.

    Operators come in two usage types: unary and binary. Unary operators work on a single operand, while binary operators require two operands. Most operators in Visual Basic are binary operators.

    Arithmetic Operators

    The VB arithmetic operators provide basic manipulation of integer and floating point numbers. They could be called "the calculator operators," since most of them appear on even the most basic four-function calculator.

    + (Addition)

    The addition operator adds numeric expressions together and returns the result.

      result = expression1 + expression2

    When used with string operands, the + operator acts like the & string concate nation operator, as described below.

    + (Unary Plus)

    Usually, the + operator only appears as a binary operator. But it can be used in a unary form. In this usage, when placed immediately before a number or numeric expression, it ensures that the expression retains its sign, either positive or negative. Since expressions retain their sign by default, the unary plus operator is redundant and rarely used.

      result =+expression

    New variation in 2005. Beginning with the 2005 release of Visual Basic, overloading this operator may prove useful in some classes.

    - (Subtraction)

    The subtraction operator deducts the value of one expression from another, returning the difference.

      result = expression1 -expression2

    Unlike the addition operator, the subtraction operator cannot be used with string operands.

    - (Unary Negation)

    The - operator performs double duty as both a unary and binary operator. In its unary form, when placed immediately before a number or numeric expression, it negates the expression, effectively multiplying the expression by -1.

      result =-expression

    * (Multiplication)

    The multiplication operator multiplies two numeric expressions together and returns the result.

      result = expression1 * expression2

    / (Division)

    The division operator divides one numeric expression into another and returns the result, retaining any decimal remainder. If the second operand is zero (0), a "divide by zero" error occurs.

      result = expression1 / expression2

    \ (Integer Division)

    The integer division operator works just like the normal division operator, but any decimal remainder is truncated (not rounded) before returning the result. If the second operand is zero (0), a "divide by zero error" occurs.

      result = expression1 \ expression2

    This operator always returns a non-decimal data type (such as Short, Integer, or Long), even if the original operands were decimal.

    Mod (Modulo)

    The modulo operator divides one numeric expression into another and returns only the remainder as a whole number, also known as the modulus. If either of the two source expressions are decimal numbers, they are rounded to integer values prior to the modulo operation. To obtain expected results, explicitly truncate or round decimal expressions before using them as operands. The return value is a nonnegative integral data type.

    As an example, the expression:

      10 Mod 3

    returns 1, because the remainder of 10 divided by 3 is 1.

      result = expression1 Mod expression2

    ^ (Exponentiation)

    The exponentiation operator raises one numeric expression to the power of the second and returns the result.

      result = number ^ exponent

    More Visual Basic.NET Articles
    More By O'Reilly Media


       · 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

    - Clocks and Countdowns
    - 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...





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