O'Reilly logo

Programming Visual Basic 2008 by Tim Patrick

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Operators

Visual Basic includes a variety of operators that let you manipulate the values of your variables. You've already seen the assignment operator (=), which lets you assign a value directly to a variable. Most of the other operators let you build up expressions that combine multiple original values in formulaic ways for eventual assignment to a variable. Consider the following statement:

squareArea = length * width

This statement includes two operators: assignment and multiplication. The multiplication operator combines two values (length and width) using multiplication, and the assignment operator stores the product in the squareArea variable. Without operators, you would be hard-pressed to calculate an area or any complex formula.

There are two types of non-assignment operators: unary and binary. Unary operators work with only a single value, or operand. Binary operators require two operands, but result in a single processed value. Operands include literals, constants, variables, and function return values. Table 6-7 lists the different operators with usage details.

Table 6-7. Visual Basic non-assignment operators

Operator

Description

+

Addition. Adds two operands together, producing a sum. Some programmers also use this operator to perform string concatenation, but it's better to join strings using another operator (&) specifically designed for that purpose.

Syntax: operand1 + operand2

Example: 2 + 3

+

Unary plus. Ensures that an operand retains its current sign, either positive ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required