![]() http://www.ronshardwebapps.com
Other Tutorials: Ron's Hard TutorialsFebruary, 2003
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The Topic:In this month's tutorial, I discuss VBScript assignment and mathematical operators. These are important for assigning values to variables, performing mathematical calculations, and making comparisons in decision structures (e.g. IF...Then Statements).First, I'll go over the assignment operator and after that, I'll cover mathematical operators and the order of precedence. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Who is this lesson for:This VBScript tutorial is for beginners who are just becoming familiar with ASP and VBScript, or for experienced programmers who need a reference on operators. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The Assignment Operator:In VBScript the equal sign(=) is used to assign a value to a variable. This should not be confused with the way the equal sign(=) is used with equations in mathematics. For example, if I wanted to assign the value 3 to a variable name intValue, then I would use the following code:
Similarly, if I want to assign the string value "Ron" to a variable named strFirstName, then I would use the following:
The parentheses around the string "Ron" are required. The expression does not mean "Ron" is the same as strFirstName, rather it means strFirstName holds the string "Ron" and we can use the variable strFirstName to represent this string until we assign another value to the variable strFirstName, or the variable loses its value because it is out of scope. Beginners are often confused by code like this:
In the code above, the variable intValue is being increased by a value of 3. This is not a traditional mathematical equation, it is common programming syntax and we will discuss this syntax further in Part II of VBScript operators. For now, all you need to know is that we use the equal sign(=) to assign values to variables, whether is it a number, character or object. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Mathematical Operators:Here is a list of the VBScript mathematical operators:
These operators are generally self-explanatory, but some need further explanation.
One of the most important things to be aware of when using these mathematical operators is the order of precedence. Beginners often have trouble with this and it is important to note that the order in which the operators are used can change the result, so make sure you are careful with placing these operators in code. The rules for VBScript mathematical operators can be summarized by these principals:
Using the order of precedence, the following expression has a result of 11.875:
VBScript offers powerful operators that we can use to assign values to variables and perform mathematical operations. VBScript also provides comparison and logical operators that allow us to compare values for making decisions inside our applications and we will cover those in part II. If you have any questions about February's tutorial, send me an email and I'll be happy to help. -Ron Other Tutorials: Ron's Hard Tutorials![]() [ Home | Top | Guest Book ] |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Please Email Ron © 2002 Ron Williams 64.71.40.22 |