Previous Topic

Next Topic

Book Contents

Book Index

Home Page

Learning VBScript

Microsoft VBScript is a small, standard scripting language. Although it is a simple language, it is beyond the scope of this manual to cover full details about VBScript.

We present a very brief introduction to some essential elements of the VBScript language below. For more in-depth references and tutorials please refer to the VBScript Resources.

VBScript Essentials

The last part of this section shows how to test VBScript code using Active Call Center. Users may find this feature useful for trying some of the samples shown below.

Defining and Using Variables

As a matter of convention, any variable that will be used in VBScript should be defined using the "Dim" statement.

In the example below, we define a variable called "X" and set its value to 12.

Dim X
X = 12

In the next example (below), we define a variable called "Message" and set its value to "Hello". Notice that all text values are included in quotation marks - this is a requirement for VBScript.

Dim Message
Message = "Hello"

In Active Call Center Macros, any variables defined with the Dim statement will be destroyed as soon as the Macro has finished executing. We refer to such variables as "local variables."


Operators are used to combine two or more expressions together. The basic mathematical operators are all valid in VBScript: + (addition), - (subtraction), / (division), * (multiplication). The + or & operators are used to combine text strings.

In the example below, we define variables called "X" and "Y", set X to 12, and then multiply that value by 2 to get Y. Note that the apostrophe precedes the comment on the third line.

Dim X
X = 12
Y = 2*X ' Read: "Y equals two times X"

In the next example (below), we define a variable called "Message" and set its value to "Hello". We then expand the value of Message to include a name.

Dim Message
Message = "Hello"
Message = Message & ", my name is John."

At the end of the second example, the value of the Message variable is "Hello, my name is John."

Message Boxes

Message boxes are little pop-up screens that display some data. They are very useful for showing values of specific variables at various steps in a Macro to aid in the debugging process. To show a message box, use the "MsgBox" statement followed by the text to display. The following example shows how to use message boxes to check the Message variable:

Dim Message
MsgBox "Starting the example now."
Message = "Hello"
MsgBox Message
Message = Message & ", my name is John."
MsgBox "Final value: " & Message

This example will show three separate message boxes, the last two will show the evolution of the Message variable. Notice how the very last message box combines some text and the Message variable.

Conditional Processing

If-then statements are used for conditional processing in VBScript. Let's look at a simple example of If-then conditional processing, notice how the "If" - "Then" statement block ends with an "End If":

Dim X
X = 12
If X = 12 Then
MsgBox "How about that, X is 12."
End If

In this example, the "If" condition is true, so we will see the message "How about that, X is 12."

In the next example, we change the second line to read "X = 13" and add an "Else" section. The "Else" section is executed when the "If" condition is not true:

Dim X
X = 13
If X = 12 Then
MsgBox "How about that, X is 12."
MsgBox "Wow, X is not 12."
End If

In the above example processing will continue in the "Else" section and we will see the message "Wow, X is not 12."

More complicated conditional processing can be done with the ElseIf statement:

Dim MessageFrom
MessageFrom = "Mary"
If MessageFrom = "Bill" Then
MsgBox "This message is from Bill."
ElseIf MessageFrom = "Mary" Then
MsgBox "This message is from Mary."
MsgBox "This message is not from Bill or Mary."
End If

Line Continuations

Quite often lines of code get very long. Break up lines of code using the line continuation character: _ (underscore). The following example illustrates use of line continuation:

MsgBox "Hello, my name is John. " + _
"I am visiting from Delaware. " + _
"It's a pretty small state."

Reading and Writing Text Files

Reading and writing text files is accomplished with the use of the FileSystemObject. For more information on the FileSystemObject refer to Microsoft's VBScript Documentation.

Testing the Sample Code Above

Active Call Center can be used to test the sample VBScript code shown above. To test any of the sample code, follow these steps:

Start Active Call Center from the Windows taskbar by clicking Start ... Programs ... Active Call Center ... Active Call Center.

From the Active Call Center menu bar, click File ... New Call Tree.

Name the Call Tree Testing VBScript and save it.

Click the Answer_Phone Node so the Edit Node window appears.

Click the VBScript Macro tab and click in the VBScript Macro field. Use the BACKSPACE key to delete the words " ' Insert your VBScript code here."

Type or copy the sample VBScript code into the field. Active Call Center's VBScript editor will color-syntax highlight the code you enter for readability.

When finished entering the sample code, click the Test the Macro button to see the results.

In This Section

Comparing Visual Basic, Visual Basic for Applications, and VBScript

See Also

VBScript Macros

VBScript Resources

Variables Used in Macros

Integrating COM Applications

Integrating Other Applications

Testing and Debugging VBScript Macros

VBScript Built-In Functions (Global Functions)

Automating Windows Tasks

Call Ending VBScript Macro