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

The Script Level

We’ve seen that code can be organized into functions, subroutines, and classes, and that some subroutines (and an occasional function) can be executed automatically if they are event handlers and the event they handle fires. However, that seems to offer a relatively limited “hook” for script to run, nor does it seem to make it possible for a script to perform whatever initialization might be required in order for its event handlers to function successfully.

The script level is the answer to this dilemma. Script-level code—that is, code outside functions and subroutines—is executed automatically when the script loads or as the HTML on the page is parsed. The precise meaning of script-level code and the exact way in which code at script level is executed depends on the host environment for which the script is written. We’ll examine these in turn.

Active Server Pages

In ASP, script-level code is synonymous with code in direct ASP commands—it is script that is preceded by the <% or <%= tags and terminated by the %> tag. (For details on how script is embedded within in ASP page, see Chapter 5.) This code is executed automatically as the page’s HTML is parsed.

It is also possible to include script-level code in <SCRIPT>...</SCRIPT> tags in an ASP. However, this is not genuine script-level code: aside from variable declarations, the order in which this code is executed is undefined.

Figure 2.1 shows the web page produced by Example 2.7, which illustrates script-level code ...

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