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 ...
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.