You often need to store values temporarily when performing calculations with Visual Basic. For example, you might want to calculate several values, compare them, and perform different operations on them, depending on the result of the comparison. You need to retain the values if you want to compare them, but you don't need to store them in a property.
Visual Basic, like most programming languages, uses variables for storing values. A variable has a name (the word you use to refer to the value the variable contains) and a data type (which determines the kind of data the variable can store). A variable can represent an array if it needs to store an indexed set of closely related data items.
You use assignment statements to perform calculations and assign the result to a variable, as shown in the following code:
ApplesSold = 10 ' The value 10 is assigned to the variable. ApplesSold = ApplesSold + 1 ' The variable is incremented.
Note The equal sign (=) in this example is an assignment operator, not an equality operator. The value is being assigned to the variable
In This Section
- Variable Declaration
- Describes how to declare a variable to tell the program about it in advance.
- Object Variables
- Describes how to use variables to refer to objects.