- The Fundamentals of VBScript
- VBScript Versus VB
- Creating Variables in VBScript
- Concatenating Strings
- Arrays and Loops
- Resizing Arrays
- Inequality Operators
- Conditional Statements
- Select Case Statements
- Working with Arguments
- Beware of Types
- Event Procedure Naming Syntax
- Server-Side Events
- Local Variables
- Script-Level Variables
If a variable is created outside of a procedure, it lives as long as the page is being processed and can be seen by any other variable within the page.
Listing 3.14 shows code that uses script-level code. Notice the variable y is created within the <SCRIPT> tags, yet outside of any one procedure. This means that the variable is in force for as long as the Web page is active and that it can be seen from anywhere in the page, from within any procedure. You use variables with script level scope when you need to share data between procedures.
Figure 3.10 displays the output of from Listing 3.14.
Listing 3.14: Using Script-Level Scope (03asp14.htm)
<HTML> <HEAD> <TITLE></TITLE> </HEAD> <SCRIPT LANGUAGE=VBScript> 'Declare a variable with script level scope Dim y Sub button1_OnClick() Dim x x = 100 y = text1.value text2.value = x + y End Sub Sub button2_OnClick() Dim x x = 50 y = text1.value text3.value = x + y End Sub </SCRIPT> <BODY> <P>The value of Y = <INPUT name=text1 size=6></P> <P><INPUT name=button1 type=button value="Button 1 (x = 100)"></P> <P><INPUT name=button2 type=button value="Button 2 (x = 50)"></P> <HR> <P>The value you get when you click Button1 is: <INPUT name=text2 size=6></P> <P>The value you get when you click Button 2 is: <INPUT name=text3 size=6></P>
Figure 3.10 A script-level variable can be seen from anywhere within the page.
This chapter provided a fast overview of VBScript. It is by no means exhaustive, as there is a lot to the language. As you move on with this book, we'll keep adding to your VBScript knowledge. However, be advised that Microsoft has put VBScript documentation online:
The next chapter introduces you to the fundamentals of writing ASP script. You'll put the VBScript that you have learned here to use, but you will do so within a server side ASP framework. Therefore, you'll need to have access to a server running IIS minimally on Windows NT 4.0, if not Windows 2000. On the other hand, if you are developing ASP Pages on your desktop computer, you'll need a copy of PWS running.
PWS is available for download at