Understanding Variables in VBScript (Page 1 of 4 )
In VBScript, as with any programming language, it is extremely important to familiarize yourself with variables and how they work. Variable usage in VBScript is highly simplified, but before we begin, let’s take a look at what variables are exactly.
Much like their mathematical cousins, in programming, variables are used to reference some piece of data. In programming, that data is stored in memory and a variable serves as a reference to the memory address where the data is located.
As their name implies, variables are dynamic. Values can be assigned and reassigned at any time throughout their lifespan. Unlike some other programming languages, variables in VBScript do not need to have a value assigned to them when they are initialized, although this is a common practice.
Understand the difference between variables and constants: the value of a variable can be changed while the value of a constant cannot be changed once it has been initialized.
You should also be aware of data types. As with any programming language, multiple data types exist, however, all variables are of type Variant. This means that you do not need to declare a data type when initializing a variable and that you may change the data type associated with it at any time.
This comes as both a blessing and a curse. On one hand, you can perform data type conversions on the fly, which can prevent a lot of runtime errors. On the other hand, these “behind the scenes” conversions can often produce some pretty unexpected results.
Next: Variable Names and Scope >>
More BrainDump Articles
More By Nilpo