O'Reilly logo

VBScript in a Nutshell by Ron Petrusha, Paul Lomax, Matt Childs

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Program Flow

WSH supports two kinds of script files: what we might term simple script files, which were supported by WSH 1.0 and are suitable for simple scripting applications; and script files with XML code, which is more structured, far more powerful, and have a number of features of interest to more advanced programmers. In this section, we’ll examine how both types of script files can be used.

Simple Script Files

Simple script files written in VBScript usually have a .vbs extension and contain only VBScript language elements, along with references to the properties, methods, and events belonging to objects instantiated by the script. XML tags are not permitted within simple script files.

The program entry point of a simple script is the global area at the top of the file, and program execution terminates after the last line of code that is not contained within a function or a procedure has executed. This is illustrated by the simple script in Example 7.1. Program flow begins with the Dim statement on the first line and ends with the MsgBox function call on the fourth line. The fourth line also causes the AddTwo user-defined function to be executed before the MsgBox function. The MultTwo function is never executed, since it is not explicitly called by the first four lines of code.

Example 7-1. Program Flow in a Simple WSH Script

dim iVar1, iVar2 iVar1 = 1 iVar2 = 2 msgbox AddTwo(iVar1, iVar2) ' Multiplies two numbers Function MultTwo(var1, var2) MultTwo = var1 * var2 End Function ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required