Variables and Constants
With all this data flying around inside your script, you need some way to keep track of it. In reality, the data you are using—whether it is data you create as part of the program, or data that is entered by the user, or data that you access from a database—is held somewhere in the computer’s memory. Think of the nightmare you’d have trying to keep track of just which memory location your particular piece of data was occupying (completely ignoring the possibility that its memory location might change while the program executes). Those nice people who write the software we use to create our programs and scripts solved this problem a long time ago by giving us variables and constants.
What Is a Variable?
A variable is a placeholder or recognizable name for a memory location. This location is of no consequence to us; all we have to do is remember the name. When we use the name, the script engine will go to the correct memory location and either retrieve the data stored there or change the data, depending upon our instructions. It is important therefore to learn the rules for naming variables:
Variable names can be no more than 255 characters in length. Variable names tend to become pretty unreadable after about 20 characters anyhow, which then defeats the purpose of having longer variable names.
The name must be unique within the scope it is being used. Don’t worry too much about scope; we’ll go through that a little later. For now, remember not to use the same ...
Get VBScript in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.