Skip to Main Content
VBScript in a Nutshell, 2nd Edition
book

VBScript in a Nutshell, 2nd Edition

by Paul Lomax, Matt Childs, Ron Petrusha
March 2003
Intermediate to advanced content levelIntermediate to advanced
512 pages
14h 30m
English
O'Reilly Media, Inc.
Content preview from VBScript in a Nutshell, 2nd Edition

Chapter 2. Program Structure

In order to write VBScript programs, you have to know how to structure your code so that your scripts and programs execute properly. Each of the different runtime environments for which you write VBScript code has different rules regarding program structure. We’ll look at each of these in turn. We’ll also examine the ways in which your host environment allows you to import VBScript code libraries, thus allowing you to create reusable code. Finally, we’ll end the chapter with a discussion of VBScript usage to write class modules. First, though, it’s important to cover the basic structures of VBScript that are relevant to all of the different script types: that global code calls code in individual functions or procedures.

Functions and Procedures

Functions and procedures (or subroutines) are central to modern programming. Dividing our script into subroutines helps us to maintain and write programs by segregating related code into smaller, manageable sections. It also helps to reduce the number of lines of code we have to write by allowing us to reuse the same subroutine or function many times in different situations and from different parts of the program. In this section, we’ll examine the different types of subroutines, how and why they are used, and how using subroutines helps to optimize code.

Defining Subroutines: The Sub . . . End Sub Construct

The Sub...End Sub construct is used to define a subroutine; that is, a procedure that performs some operation ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

VBScript in a Nutshell

VBScript in a Nutshell

Matt Childs, Paul Lomax, Ron Petrusha
Microsoft® PowerShell, VBScript and JScript® Bible

Microsoft® PowerShell, VBScript and JScript® Bible

William R. Stanek, James O'Neill, Jeffrey Rosen

Publisher Resources

ISBN: 0596004885Errata Page