Datasheet
Chapter 1: A Quick Introduction to Programming
6
 Line 4 is another comment. Line 5 is more code. Now that you’ve initialized this variable, you’re going to 
do something useful with it. 
MsgBox  is another built-in VBScript function that you will probably use a lot 
during the course of your VBScript programming. Using the 
MsgBox  function is a good way to introduce 
the programming concept of passing function parameters, also known as arguments . Some functions 
don’t require you to pass parameters to them while others do. This is because some functions (take the 
Date  function as an example — this returns the current date based on the system time) do not need any 
additional information from you in order to do their job. The 
MsgBox  function, on the other hand, dis-
plays a piece of information to the user in the form of a dialog box, such as the one shown in Figure 1-2 .  
Figure 1-2
 You have to pass 
MsgBox  a parameter because on its own it doesn’t have anything useful to display (in 
fact, it will just bring up a blank pop-up box). The 
MsgBox  function actually has several parameters, but 
for now you’re just going to look at one. All of the other parameters are optional parameters. 
   Understanding Syntax Issues 
 Take another look at line 5 and you’ll probably notice the ampersand ( & ). The ampersand is a VBScript 
operator, and is used to concatenate (join) pieces of text together. To concatenate simply means to “string 
together.” This text can take the form of either a literal or a variable. A literal is the opposite of a variable. 
A variable is so named because it is exactly that — a variable — and can change throughout the lifetime 
of the script (a script’s lifetime is the time from when it starts executing, to the time it stops). Unlike a 
 variable, a literal cannot change during the lifetime of the script. Here is line 5 of the script again. 
  MsgBox “Hello “& YourName & “! Pleased to meet you.”
   An operator is a symbol or a word that you use within your code that is usually used to change or test a 
value. Other operators include the standard mathematical operators ( 
+ ,   - ,   / ,   * ), and the equals sign ( = ), 
which can actually be used in either a comparison or an assignment. So far, you’ve used the equals sign 
as an assignment operator. Later in this chapter you’ll find out more about operators. 
 Now take a closer look at variables. Remember how we said that a variable is a piece of reserved 
 memory? One question you might have is, How does the computer know how large to make that piece 
of memory? Well, again, in VBScript this isn’t something that you need to worry about and it is all 
 handled automatically by the VBScript engine. You don’t have to worry in advance about how big or 
small you need to make a variable. You can even change your mind and the VBScript engine will 
dynamically change and reallocate the actual memory addresses that are used up by a variable. For 
example, take a quick look at this VBScript program. 
c01.indd 6c01.indd 6 8/27/07 7:45:19 PM8/27/07 7:45:19 PM










