A variable is something that can hold different values. One kind of variable is the string. The string can hold characters(numbers, letters, ect.). To hold numbers that you would like to subtract and add use the integer variable. It will hold only numbers, no letters, and unlike the string variable you can subract, add, multiply, and divide an integer. Integers will not hold decimals(I will explain how to hold decimals later.) Before you assign a value to a variable, you should declare it. You can declare a variable like this:
Dim Name As String
Dim Counter As Integer
Dim declares the variable that follows it. Name would be the variable in the first statement and Counter in the second. After you name your variable you have to declare what type of variable it is. In the first statement Name is declared as a string variable and in the second Counter is declared as an integer variable. You can give a variable a value like follows:
Name = "Sarah"
Counter = 1
Notice that in the first statement you first name your variable, put an equal sign second(I wonder what that means???), and then you put what Name would equal(Sarah in this case.) For a sring you must enclose what you wish it to equal in paranthesis. If you do not, it will assume that Sarah is a variable instead of what you want it to equal. Now in the second statement we put the variable first, an equal sign second, and then what the integer is to equal which is 1. That is pretty easy.
You can also make one variable equal another if they are the same type of variable by typing:
Dim Name1 As String
Dim Name2 As String
Name1 = "Sarah"
Name2 = Name
In this case, Name1 equals Sarah, and then Name2 equals Name1. So in the end Name2 equal Sarah. Now that you know how easy this is, you probably have two questions. First "How do you make a variable that holds decimals?" and two, "How do I add and subtract a variable?" For the first question about holding decimals you can declare the variable as a Long or, if you plan to hold a dollar amount, even better than the Long is the Currency variable.
For the second question, which is even easier, you can do this:
Counter = 1 + 54
Counter = 50 - 25
Counter = 10 * 10
Counter = 50 \ 2
The first would add, the second subtract, the third multiply, and the fourth divide. If you test the dividing you may find an error if you try to return a decimal amount. If the divider is \ then it will return only an integer amount(rounding the number off), but if you use a / then it will return a decimal. Remember, you cannot add, subtract, multiply, or divide with a string. Yes, a string will hold numbers, but a string does not keep the number's numerical values.
Copyright ©2000 by Kyle Baker. Please read our disclaimer.