You are here:About>Computing & Technology>Visual Basic> Learn VB.NET> Visual Basic .NET 2008 Express - Visual Basic Fundamentals
About.comVisual Basic
Newsletters & RSSEmail to a friendSubmit to Digg

Visual Basic .NET 2008 Express - Visual Basic Fundamentals

From Dan Mabbutt,
Your Guide to Visual Basic.
FREE Newsletter. Sign Up Now!
Feb 14 2008

Operations on Data

After you declare a name for a piece of data, the next thing is usually to do some operation with the data. An example of an operation is one half of an assignment operation that we have already seen (see "assignment statement" above). Microsoft classifies all Visual Basic operators as

  • Arithmetic Operators

- Arithmetic operations include the familiar "+", "*", and "/" but also including interesting variations such as the modulus (Mod) and integer division "\" and a nice collection of operations that get down to single bits (1's and 0's), the bitwise And, Or, and bit shift (">>" and "<<"). One key concept to remember is that Visual Basic will apply these operators in a specific sequence if you don't add parenthesis to group things. The statement ...

i = 4 + 6 * 7

... results in a value of 46 in the variable i. But ...

i = (4 + 6) * 7

... results in a value of 70 in i.

  • Comparison Operators

- The purpose of a comparison is to produce a Boolean true or false value that can be used somewhere else in your program, usually in something like an If block or a program loop.

There are six comparison operators:

  • = (Equality)
  • <> (Inequality)
  • < (Less than)
  • > (Greater than)
  • <= (Less than or equal to)
  • >= (Greater than or equal to)

It's worth knowing that the Boolean value that is a result of a comparison operation is just True or False. It's not a simple number like it used to be in VB6. Microsoft has this to say about the Boolean data type:

When numeric data types are converted to Boolean values, 0 becomes False and all other values become True. When Boolean values are converted to numeric types, False becomes 0 and True becomes -1.

Some old VB6 programs use the values 0 and -1 instead of True and False. Never do that in VB.NET.

Microsoft puts the logical operators, And, Or, AndAlso, OrElse, Xor and the Not operator in their own category because they only operate on Boolean variables. If you ever get confused about how these work, I recommend that you try diagramming them using what is called a Truth Table or Karnaugh Map.

  • Concatenation Operators

Just two operators, "+" and "&", which both do almost the same thing: join two strings into one. "+" is also an arithmetic operator so if you only want to concatenate strings, use "&".

On the next page, we use Boolean variables to write the conditional statements that are really the only way that computers have any flexibilty to do more than one thing.

 All Topics | Email Article | | |
Advertising Info | News & Events | Work at About | SiteMap | Reprints | HelpOur Story | Be a Guide
User Agreement | Ethics Policy | Patent Info. | Privacy Policy©2008 About, Inc., A part of The New York Times Company. All rights reserved.