Data Assignment and Evaluation
A variable is used as the left or right operand in a statement and as a parameter to a _function or subroutine. When a variable is on the left side of an operator, it is the left operand. When a variable is on the right side of an operator, it is the right operand.
A function is a block of code comprised of one or more statements referred to by name. A function has a return data type, indicating the type of the value you wish to return from the function.
A subroutine is a block of code comprised of one or more statements referred to by a name in your program. A subroutine does not have a return data type.
A parameter, also called an argument, is a variable that is passed to a function _or subroutine to be evaluated or modified by the lines of code in the function or subroutine.
When the operator is an equals operator (=), the variable on the left side is being assigned the value on the right side of the equals operator. Listing 3.1 contains five statements that demonstrate declaration assignment and evaluation.
Listing 3.1 Variable Assignment and Evaluation
1: Dim Circumference As Double 2: Dim Radius As Double 3: Const PI = 3.14159 4: Radius = 10 5: Circumference = PI * Radius ^ 2
NOTE
A line of code can be counted literally as one line of text, but one statement may contain more than one line of text.
Line 1 declares the variable Circumference as Double. Line 2 declares the variable Radius as Double. Line 3 defines a constant value for PI. Line 4 assigns the value 10 to Radius. In line 5, Circumference is being assigned the value of PI * Radius squared. (The caret (^) is the square operator.)
TIP
If you want to define multiple variables of the same type, you can do so on one line by comma-delimiting the variable name. Here's an example:
Dim Circumference, Radius As Double
TIP
However, the preceding type of declaration is commonly mistaken to mean that all variables in the comma-delimited list are the same data type. For example, in the preceding fragment it is commonly and mistakenly assumed that Circumference and Radius are both Double. In fact, Radius is a Double type and Circumference is a Variant type. When a data type is not clearly indicated, the type of the data will default to a Variant type.
NOTE
When you declare a Const value, you refer to the assignment of an initial value to Const as an initialization.
NOTE
Many of these terms can be a little confusing, but they evolved to help programmers clearly and concisely articulate meaning. Although you do not have to master all terminology, it is beneficial to use the appropriate terms when communicating with other programmers.
In Listing 3.1 (lines 3, 4, and 5), the constant PI, the variable Radius, and the variable Circumference are all being assigned to. In line 5, PI, Radius, and the literal 2 are all part of an evaluation.