Operators include symbols for multiplication, division, addition, and subtraction. Operator precedence is the order in which operations are performed. The following is an operator precedence chart.
The following is a list of comparison operators:
There are also logical operators which allow more than one condition on the same line. The following chart is a summary of Logical operators.
The following program illustrates logical and comparison operators. The first two lines are True, and the third line is False.
Sub myOperators()
If 4 > 3 And 2 < 7 Then MsgBox "Message Box 1 is True"
If 2 >= 2 Or 7 > 3 Then MsgBox "Message Box 2 is True"
If 7 > 2 And 8 > 9 Then MsgBox "This box will not print, because this is False."
MsgBox " Above statement is False"
End Sub
The following examples illustrate precedence of operators.
Sub myPrecedence()
Dim x As Double 'Notice we are declaring with Double, not Long in
Dim y As Double 'case we get a decimal answer.
Dim z As Double
x = 2 * 3 + 4 / 2 - 3 + 2 ^ 3 'x = 13
MsgBox “x = “ & x
y = 2 * (3 + 4) / 2 - 3 + 2 ^ 3 'y = 12
MsgBox “y = “ & y
z = 2 * (3 + 4) / (2 - 3) + 2 ^ 3 'z = -6
MsgBox “z = “ & z
End Sub
Table of Contents
Ch1-Introduction
Ch2-Loops
Ch3-If Statements
Ch4-Functions
Ch5-Subs & Functions
Ch6-Read & Write
Ch7-Operators
Ch8-Built-in Functions
Ch9-Built-in Examples
Ch10-Debugging
Ch11-Running Subs
Ch12-Sample Programs
Ch13-WS Formulas
Ch14-Questions