VBScript is Microsoft's scripting language for the Internet. Similar in function to JavaScript, VBScript has been designed to leverage the skills of millions of Visual basic programmers to the Internet. Although JavaScript is a powerful scripting language, it is not as easy to learn and use as is VBScript. VBScript can be used easily to create active web pages. Since VBScript is supported by Microsoft, in the near future, you will also see a great deal of VBScript/Windows NT/95 integrationunlike JavaScript. VBScript code is lightweight and fast because it has been optimized to be transmitted through the Internet. Spend some time working with VBScript and learn how it can be used to enhance a Web site by making it easier and more exciting to navigate. By the time you read this, you can expect to see VBScript supported by several other Web browsersin addition to Internet Explorerspecifically, browsers from Oracle, Spyglass, and NetManage.
VBScript is a subset of Microsoft Visual Basic and is upwardly compatible with Visual Basic for Applications (VBA). VBA is shipped with Microsoft Office applications to make it easier for developers to build custom solutions. The ability to provide scripting, automation, and customization capabilities for Web browsers is a major feature of VBScript. If you are already familiar with Visual Basic, you can soon leverage your skills to the Internet by using VBScript. Even if you are not familiar with another programming language, after reading this chapter you will be able to create "active" Web pages with VBScript. However, familiarity with a programming language will make it easier for you to grasp concepts such as recursion, type casting, and Boolean arithmetic. The most up-to-date information about VBScript can be obtained from the following URL: http://www.microsoft.com/VBScript.
VBScript programs are defined between two HTML tags. Browsers that support VBScript read the VBScript program contained between the two HTML tags and execute it after checking for any syntax errors. VBScript works as shown in Figure 12.1.
Figure 12.1. How VBScript works.
As you can see in Figure 12.1, a VBScript program is part of a regular HTML file, enclosed between the two HTML tags <SCRIPT LANGUAGE=VBS> and </SCRIPT>. When a Web browser that supports VBScript encounters the <SCRIPT LANGUAGE=VBS> HTML tag, all text between that tag and </SCRIPT> is treated as a VBScript program and interpreted for syntax errors. If any are detected, they are flagged by the VBScript interpreter, as shown in Figure 12.2.
Figure 12.2. Syntax errors in VBScript programs are flagged by the VBScript interpreter.
If the code doesn't have any syntax errors, it is executed on the Web browser. To hide VBScript code from technologically challenged Web browsers, VBScript code can be enclosed in two HTML comment tags, as shown below.
<SCRIPT LANGUAGE=VBS> <!-- To hide VBScript code from technologically challenged browsers VBScript code !--> </SCRIPT>
Writing the classic Hello World application with VBScript is easy. In this example, you will be shown how to create a Web page similar to the one in Figure 12.3. This Web page will have three buttons: The first button will display a message box with a greeting, the second button will display the current time, and the third button will display the current date. Key elements of the Hello World! VBScript program are outlined in the following section.
Figure 12.3. The VBScript Hello World! application.
As shown in Figure 12.4, the Hello World dialog box is shown each time a user clicks the Please click here for message box button. If you look at the HTML page the VBScript program is in, you see that the command button associated with the Hello World dialog box is named BtnHello (NAME="BtnHello"). As you can see from the listing below, the OnClick event is associated with the BtnHello subroutine. Each time a user clicks the Please click here for message box button, the Web browser invokes the BtnHello_OnClick subroutine, and any VBScript code defined in that subroutine is executed.
The BtnHello_OnClick subroutine is a simple VBScript subroutine. The first three lines create strings displayed by the dialog box in Figure 12.4. Note how the string concatenation operator (&) is used in line 4 to merge two strings into one and assign the result to a variable. The result is then displayed in a message box, as shown in Figure 12.4.
1: Sub BtnHello_OnClick 2: titleString = "Web Site Developer's Guide for Windows NT" 3: helloString = "Hello world! Welcome to the fun filled " 4: helloString = helloString & "world of VBScript programming!" 5: MsgBox helloString, 0, titleString 6: End Sub
Figure 12.4. The Hello World! dialog box.
The BtnTime_OnClick subroutine is similar to the BtnHello_OnClick subroutine, except it concatenates a string with the result of a function, rather than concatenates two strings. The time function returns the current time. As shown in Figure 12.5, line 3 of the following program listing displays the current time in a dialog box:
1: Sub BtnTime_OnClick 2: timeString = "So, you want to know the time? The time is " & time 3: MsgBox timeString , 0, "Time Dialog Box" 4: End Sub
Figure 12.5. The Time dialog box.
The Date dialog box displays the current date in a dialog box, as shown in Figure 12.6. As you can see in line 2 of the following code listing, the result of one function (date) can be used as an argument of another function (DateValue):
1: Sub BtnDate_OnClick 2: dateString = "Today's date is " & DateValue(date) 3: MsgBox dateString , 0, "Date Dialog Box" 4: End Sub
Figure 12.6. The Date dialog box.
For your reference, the full source code of the Hello World application is shown in Listing 12.1.
<!--
1996 Sanjaya Hettihewa (http://wonderland.dial.umd.edu)
All Rights Reserved.
!-->
<HTML>
<HEAD>
<TITLE>VBScript Tutorial: Hello World!</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#0000FF"
LINK="#B864FF" VLINK="#670000" ALINK="#FF0000">
<IMG SRC="vbscript.jpg"><P>
<B><FONT FACE="Comic Sans MS" SIZE=6 COLOR=RED>
VBScript Tutorial: <FONT></B>
<I><FONT FACE="Comic Sans MS" SIZE=5 COLOR=BLUE>
"Hello World!" </I><P><FONT>
<FORM>
<INPUT TYPE=BUTTON VALUE="Please click here for message box"
NAME="BtnHello">
<INPUT TYPE=BUTTON VALUE="What time is it?"
NAME="BtnTime">
<INPUT TYPE=BUTTON VALUE="What date is it?"
NAME="BtnDate">
</FORM>
<SCRIPT LANGUAGE=VBS>
<!-- To hide VBScript code from technologically challenged browsers
Sub BtnHello_OnClick
titleString = "Web Site Developer's Guide for Windows NT"
helloString = "Hello world! Welcome to the fun filled "
helloString = helloString & "world of VBScript programming!"
MsgBox helloString, 0, titleString
End Sub
Sub BtnTime_OnClick
timeString = "So, you want to know the time? The time is " & time
MsgBox timeString , 0, "Time Dialog Box"
End Sub
Sub BtnDate_OnClick
dateString = "Today's date is " & DateValue(date)
MsgBox dateString , 0, "Date Dialog Box"
End Sub
!-->
</SCRIPT>
</BODY>
</HTML>
VBScript supports several operators for string, Boolean, and number manipulation tasks; they are explained in the following sections.
Syntax: <operand1> + <operand2>
The addition operator can be used to add two operands. If both operands are numeric, the result is also numeric. However, if they are strings, VBScript does a string concatenation instead of a numeric addition. To avoid ambiguity, you should use the string concatenation operator (&) when joining strings and the addition operator (+) when adding numeric expressions.
Syntax: <operand1> - <operand2> Syntax: -<OperandToNegate>
The subtraction operator is used as unary minus and the binary subtraction operator. When used as the binary subtraction operator, it subtracts <operand2> from <operand1> and returns the resulting value; when used as the unary minus, it negates the numeric operand <OperandToNegate> it is used with.
Syntax: <operand1> ^ <operand2>
The multiplication operator takes two numeric operands, multiplies them, and returns the resulting value.
Syntax: <operand1> ^ <operand2>
The exponential operator returns the resulting value of <operand1> raised to the <operand2> power.
Syntax: <operand1> / <operand2>
The division operator is used to divide <operand1> from <operand2>. Both <operand1> and <operand2> have to be numeric expressions, and the resulting value is a floating-point number.
Syntax: <operand1> \ <operand2>
The integer division operator is somewhat similar to the floating-point division operator. The integer division operator returns an integer number after dividing <operand1> from <operand2>. Here are a few examples of the integer division operator:
( 23 \ 4 ) = 5 ( 4 \ 23 ) = 0 ( 4 \ 2 ) = 2 ( 5 \ 2 ) = 2
Syntax: <operand1> & <operand2>
The string concatenation operator can be used to join <operand1> and <operand2> together.
Syntax: <operand1> MOD <operand2>
The MOD operator is similar to the integer division operator, except that it returns the remainder of <operand1> divided by <operand2>. Here are a few examples of the MOD operator:
( 23 MOD 4 ) = 3 ( 4 MOD 23 ) = 4 ( 4 MOD 2 ) = 0 ( 5 MOD 2 ) = 1
VBScript supports a number of Boolean operators. The best way to explain how Boolean operators work is with a truth table. Refer to Figure 12.7 for truth tables of some useful VBScript Boolean operators.
Figure 12.7. Truth tables of VBScript Boolean operators.
Syntax: <operand1> Eqv <operand2>
The equivalence operator can be used to determine whether <operand1> is equal to <operand2>. If either <operand1> or <operand2> is NULL, then the resulting value is also NULL. The following list is the truth table of the equivalence operator:
TRUE Eqv TRUE = TRUE FALSE Eqv TRUE = FALSE TRUE Eqv FALSE = FALSE FALSE Eqv FALSE = TRUE
(TRUE may be replaced with binary 1 and FALSE may be replaced with binary 0.)
Syntax: <operand1> IS <operand2>
The object reference operator is used to compare two object reference variables. If <operand1> refers to the same object as <operand2>, the object reference operator returns true. Otherwise, it returns false.
VBScript supports several comparison operators that are used to compare strings as well as numbers. Table 12.1 lists the comparison operators that can be used in VBScript programs.
Syntax |
Description |
|
<operand1> = <operand2> |
Returns true if both <operand1> and <operand2> are equal to each other. |
|
<operand1> <> <operand2> |
Returns true if both <operand1> and <operand2> are unequal to each other. |
|
<operand1> < <operand2> |
Returns true if <operand1> is less than <operand2>. |
|
<operand1> <= <operand2> |
Returns true if <operand1> is less than or equal to <operand2>. |
|
<operand1> > <operand2> |
Returns true if <operand1> is greater than <operand2>. |
|
<operand1> >= <operand2> |
Returns true if <operand1> is greater than or equal to <operand2>. |
Syntax: <operand1> = <operand2>
Returns true if both <operand1> and <operand2> are equal to each other. However, if either <operand1> or <operand2> is NULL, the equal operator will return NULL.
Syntax: <operand1> <> <operand2>
Returns true if both <operand1> and <operand2> are unequal to each other. However, if either <operand1> or <operand2> is NULL, the unequal operator will return NULL.
Syntax: <operand1> < <operand2>
Returns true if <operand1> is less than <operand2>. However, if either <operand1> or <operand2> is NULL, the "less than" operator will return NULL.
Syntax: <operand1> <= <operand2>
Returns true if <operand1> is less than or equal to <operand2>. However, if either <operand1> or <operand2> is NULL, the "less than or equal to" operator will return NULL.
Syntax: <operand1> > <operand2>
Returns true if <operand1> is greater than <operand2>. However, if either <operand1> or <operand2> is NULL, the "greater than" operator will return NULL.
Syntax: <operand1> >= <operand2>
Returns true if <operand1> is greater than or equal to <operand2>. However, if either <operand1> or <operand2> is NULL, the "greater than or equal to" operator will return NULL.
Control structures, an important part of any language, give a language "life" by enabling programmers to add intelligence to programs with conditional and iterative statements. The VBScript control structures, and how they can be used in VBScript programs, are covered in the following sections.
The Call statement is used to transfer program control to another VBScript subroutine. Note that when Call is used to transfer control to another subroutine, any parameters in that subroutine should be enclosed in parentheses. However, if Call is omitted, subroutine arguments do not need to be enclosed in parenthesis. Return values of functions are ignored when they are invoked with the Call statement.
The Dim statement is used to declare variables, such as arrays, and assign storage space to them. When variables are declared with Dim, they are initialized with the value zero, if they are numeric variables. Otherwise, they are assigned an empty string. The Dim statement can be used to declare several types of variables.
The Do / Loop control structure can be used to iterate a group of statements until a certain Boolean expression becomes true. The syntax of the Do / Loop control structure is shown in the following code lines; the Boolean expression of a Do / Loop structure can be placed at either the beginning or the end:
Do <condition> <BooleanExpression> VBScript statements Loop
As shown here, the Boolean expression of a Do / Loop structure can also be placed at the end of the control structure:
Do VBScript statements Loop <condition> <BooleanExpression>
The preceding two examples will repeatedly execute VBScript statements enclosed in the loop structure until <BooleanExpression> becomes true.
In the same two examples, <condition> may be replaced with either While or Until. If While is used, the loop will iterate while <BooleanExpression> is true; if Until is used, the loop will iterate until <BooleanExpression> is true. Note that within a Do / Loop structure, it is possible to transfer control out of the loop by using an Exit Do statement.
Syntax: Erase <NameOfArray>
The Erase statement is used to free memory used by dynamic arrays and re-initialize elements of static arrays. If the array is a dynamic array, all space taken up by the array is freed. Dynamic arrays then need to be reallocated with the ReDim statement before they can be used again. If the array is static, all array elements are initialized with zero, if the elements are numeric. Otherwise, all array elements are initialized with empty strings.
The Exit statement causes program control to be transferred out of the control structure it's used in, which can be a loop or a subroutine. These are the different forms of the Exit command:
Exit Do: Exits a Do loop.
Exit For: Exits a For loop.
Exit Function: Exits a Function.
Exit Sub: Exits a procedure.
The For / Next control structure can be used to iterate a group of VBScript statements a certain number of times; its syntax is as follows:
For <LoopCount> = <BeginLoop> To <EndLoop> Step <StepCount> VBScript statements Next
The previous definition can be used to iterate a group of VBScript statements by replacing labels (enclosed in pointed braces) of the definition, as follows:
<LoopCount>: Name of variable used to keep track of the number of iterations. It's best that your VBScript statements not alter the value of this variable since it can easily complicate your code and make it harder to debug.
<BeginLoop>: The first value of the iteration sequence.
<EndLoop>: The last value of the iteration sequence.
Step <StepCount>: <StepCount> can be replaced with the number <LoopCount> should be incremented after each iteration of the loop. The Step statement is optional; by default, <LoopCount> will be incremented by one.
Note that the Exit For statement can be used to exit a For loop.
The For Each / Next control structure is useful for iterating VBScript statements for each object in a collection or each element in an array; here is its syntax:
For Each <LoopIndex> In <ArrayOrCollection> VBScript statements Next <LoopIndex>
A For Each / Next loop can be added to a VBScript program by substituting labels from the preceding example, as follows:
<LoopIndex>: Name of variable that's used to traverse through the elements of an array or objects in a collection.
<ArrayOrCollection>: Name of an array or collection of objects.
Note that the Exit For statement can be used to exit a For Each loop. Also note that <LoopIndex> can be omitted in the Next <LoopIndex> statement. However, this is not recommended since it can complicate things and cause errors if a For Each loop is nested inside another For Each loop.
New functions can be defined with the Function statement; its syntax is as follows:
<FunctionType> Function <NameOfFunction> <ArgumentsOfFunction> VBScript statements <NameOfFunction> = <ReturnValueOfFunction> End Function
A Function can be created by replacing labels of the above definition with values listed next:
<FunctionType>: The <FunctionType> can be left out if it is not needed. By replacing <FunctionType> with Static, you can preserve values of local variables between function calls. Unless you have a reason for doing so, Static functions are usually not suitable for recursion (a function calling itself).
<NameOfFunction>: Used to specify the name of the function.
<ArgumentsOfFunction>: Arguments of a function can be specified soon after <NameOfFunction>. By using commas, more than one argument can be specified. An argument can be passed either by value or reference. To make an argument pass by value, precede the argument name with ByVal; to pass by reference, precede the argument name with ByRef. When an argument is passed by value, its original value cannot be changed from within the function. However, when it is passed by reference, the variable used in the function is merely a pointer to the original variable. Therefore, any changes made to the value of a variable passed by reference is actually made to the original variable.
Note that the Exit Function statement can be used to exit a Function. VBScript procedures created with the Function statement are very similar to procedures created with the SUB statement; however, procedures created with the Function statement can return values, and procedures created with the Sub statement cannot.
The If / Then / Else statement can be used to execute VBScript statements based on Boolean expressions. The syntax of the If / Then / Else control structure is as follows:
IF <BooleanExpression> THEN VBScript statement ELSE IF <BooleanExpression> THEN VBScript statement ELSE VBScript statement END IF
As shown in the previous example, VBScript statements can be made to execute by using an If / Then / Else statement based on different Boolean expressions.
The Let command can be used to assign values to variables, but it isn't required. The syntax of the Let command is as follows:
Let <variableName> = <ValueOfVariable>
LSet is used to copy a variable of one user-defined type to a variable of another user-defined type. When a variable is copied with the LSet command, it is left-aligned. This is the syntax for the LSet statement:
LSet <Variable> = <ValueOfVariable>
If the length of <Variable> is longer than that of <ValueOfVariable>, after copying <ValueOfVariable> to <Variable>, the remaining space will be filled in with white spaces. Similarly, if the length of <Variable> is less than that of <ValueOfVariable>, <ValueOfVariable> will be truncated to fit in the space allocated for <Variable>. For example, if <Variable> can hold only four characters, and <ValueOfVariable> contains the string "ABCDEFG", after it is copied to <Variable> with the LSet command, <Variable> will have the value "ABCD".
Mid is a very handy statement for replacing one or more characters of a string with characters from another string. The syntax of the Mid statement is as follows:
Mid (<Variable>, <Begin>, <NumCharactersToReplace>) = <Replacement>
The Mid statement can be used by replacing labels of the preceding example as follows:
<Variable>: Name of variable containing the string that will be modified.
<Begin>: The position to begin replacing text. For example, if <Variable> contained the string 1234 and you would like 34 to be replaced with 67, <Begin> will be replaced with 3 since the sub-string 34 begins at the third position.
<NumCharactersToReplace>: Lists the number of characters that should be replaced by <Replacement>. This value can be left out, if you want; if it is, the entire <Replacement> string will be copied over.
<Replacement>: Contains string that will be copied over to <Variable>.
Usually, when a runtime error occurs in a VBScript program, it halts execution of the VBScript program. However, using the On Error Resume Next statement, it is possible to ignore the error and continue with the program, despite the runtime error.
By preceding a variable declaration with the Private keyword, it is possible to limit its scope to the script it was declared in.
By preceding a variable declaration with the Public keyword, its scope can be extended to other scripts.
Randomize can be used to initialize the random number generator; it's used either with or without a numeric argument. If it is used with a numeric argument, the numeric argument is used to seed the random number generator. However, if Randomize is used without an argument, a number from the system clock is used to seed the random number generator.
The Rem command is used to document VBScript code; its syntax is as follows:
Rem This is a comment
Note that the apostrophe (') performs the same function as the Rem command. The only difference is that if Rem is used in a line after a VBScript statement, it needs to be separated by the VBScript statement with a colon.
This is the syntax of the RSet command:
RSet <Variable> = <StringToCopy>
The RSet command works much the same way as the LSet command, except when a variable is assigned a string by using the RSet command, it's assigned to the variable right-aligned.
The Set command can be used to assign an object reference to a variable or property. The syntax of the Set command is as follows:
Set <ObjectVariable> = <Object>
When the keyword Nothing is assigned to <ObjectVariable>, system resources consumed by the object are freed when no other variables refer to the <Object>.
By preceding variable and procedure declarations with the keyword Static, you can retain values of variables. When a procedure is declared as a static procedure, all variables in that procedure keep the values assigned to them throughout the life of the program. Precede variable declarations of non-static procedures with the Static keyword to preserve their values. (Variable values of static procedures are automatically preserved.)
The Sub statement can be used to create VBScript procedures and is identical to the Function statement except for one difference. Procedures created with the Function statement can return values, but procedures created with the Sub statement cannot. The following code lines illustrate the syntax of the Sub statement; note that the Exit Sub statement can be used to transfer control out of a procedure.
<ProcedureType> Sub <NameOfProcedure> <ArgumentsOfProcedure> VBScript statements End Sub
A procedure can be created by replacing labels of the preceding definition with the values listed here:
<ProcedureType>: The <ProcedureType> can be left out if it is not needed. By replacing <ProcedureType> with Static, it is possible to preserve values of local variables in between procedure calls. Unless you have a reason for doing so, Static functions are usually not suitable for recursion (a function calling itself).
<NameOfProcedure>: Used to specify the name of the procedure.
<ArgumentsOfProcedure>: Arguments of a procedure can be specified soon after <NameOfProcedure>. By using commas, more than one argument can be specified. An argument can be passed either by value or reference. To make an argument pass by value, precede the argument name with ByVal; to pass by reference, precede the argument name with ByRef. When an argument is passed by value, its original value cannot be changed from within the procedure. However, when it is passed by reference, the variable used in the procedure is merely a pointer to the original variable. Therefore, any changes made to the value of a variable passed by reference is actually made to the original variable.
The While / Wend control structure can be used to iterate a group of VBScript statements while a certain Boolean expression is true. Here is the syntax of the While / Wend command:
While <BooleanExpression> VBScript statements Wend
The functions supported by VBScript can be used to add a new level of interactivity to a Web site by creative "active" Web pages. To delve into all the functions is beyond the scope of this book. For a more complete look at VBScript's functions, see Web Site Developer's Guide for Windows NT and Web Site Development Kit for Windows NT (Sams Publishing, 1996). In the next sections, you will be shown how the VBScript functions can be used to develop a VBScript program for an active Web site.
The control structures and commands that can be used to create VBScript programs were outlined in the preceding sections. This last section is devoted to applying these commands and control structures to demonstrate how VBScript can be used create an "active" Web page.
VBScript can be used to label a graphic when the mouse is moved over it. The VBScript program shown in this section is used to label an image. When the Web page containing the VBScript program is first invoked, it looks like Figure 12.8. Note that the Description text box contains the string Hello! Select a link, please.
Figure 12.8. The string displayed when the VBScript Web page is first invoked.
At this point, if the mouse is moved over the graphic in Figure 12.8, the value of the text box changes.
Figure 12.9. The value of the text box is No link selected. Please select a link!.
As you can see in Figure 12.10, there are four icons in the graphic on the left side of the browser window. When the mouse is moved over any of these icons, the text box lists the description of the icon. For example, when the mouse is over the bulletin board icon, the value of the text box in Figure 12.9 changes to Post messages on an online discussion forum. Key subroutines of the label image program will be discussed next.
Figure 12.10. Changing the value of the text box to the icon's description.
To detect mouse movement over the graphic in Figure 12.10, a special identification code needs to be assigned to the graphic; this is done in line 1 of the following code:
1: <A ID="ImageMapGraphic" HREF="ImageMap.Map"> 2: <IMG ALIGN=TOP SRC="vbscript.jpg" ALT="Sample Graphic" ISMAP BORDER=0> 3: </A>
ImageMapGraphic_MouseMove is the heart of the VBScript shown in Figure 12.10. When the mouse is moved over the graphic, the subroutine shown in the following code lines is activated. When the mouse pointer falls in a predetermined region of the graphic, the text box is updated with the description of that region, as shown in line 4. The HotSpot subroutine simply returns true if the mouse coordinates passed into the function fall within a certain region of the graphic.
1: Sub ImageMapGraphic_MouseMove(keyboard,mouse,xPosition,yPosition) 2: 3: IF (HotSpot(xPosition, yPosition, 2, 5, 70, 41)) THEN 4: Description.Value = "Main Homepage" 5: ELSE IF (HotSpot(xPosition, yPosition, 2, 49, 70, 82)) THEN 6: Description.Value = "Send Feedback" 7: ELSE IF (HotSpot(xPosition, yPosition, 2, 84, 70, 117)) THEN 8: Description.Value = "Site Map" 9: ELSE IF (HotSpot(xPosition, yPosition, 2, 119, 70, 164)) THEN 10: Description.Value = "Post messages on an online dicussion forum" 11: ELSE 12: Description.Value = "No link selected. Please select a link!" 13: END IF 14: END IF 15: END IF 16: END IF
For your reference, the full source code of the Label Image application is listed next.
<!--
1996 Sanjaya Hettihewa (http://wonderland.dial.umd.edu)
All Rights Reserved.
remains unchanged.
!-->
<HTML>
<HEAD>
<TITLE>VBScript Tutorial: Labeling a graphic</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#0000FF"
LINK="#B864FF" VLINK="#670000" ALINK="#FF0000">
<TABLE COLSPEC="L20 L20 L20" BORDER=2 WIDTH=10 HEIGHT=10>
<CAPTION ALIGN=top>Labeling a graphic</CAPTION>
<TR><TD>
<A ID="ImageMapGraphic" HREF="ImageMap.Map">
<IMG ALIGN=TOP SRC="vbscript.jpg" ALT="Sample Graphic" ISMAP BORDER=0>
</A>
</TD><TD>
<CENTER><FONT FACE="Comic Sans MS" SIZE=6 COLOR=Black>
Description<FONT></CENTER>
<input type="text" name="Description"
Value="Hello! Select a link, please." size=45><P>
<CENTER><INPUT TYPE=BUTTON VALUE="About" NAME="BtnAbout"></CENTER>
</TD><TD>
</TR>
</TABLE>
<P>
<B><FONT FACE="Comic Sans MS" SIZE=6 COLOR=RED>
VBScript Tutorial: <FONT></B>
<I><FONT FACE="Comic Sans MS" SIZE=5 COLOR=BLUE>
"Labeling a graphic with VBScript" </I><P><FONT>
</TD></TR>
</TABLE>
<SCRIPT LANGUAGE="VBS">
<!-- To hide VBScript code from technologically challenged browsers
Sub BtnAbout_OnClick
titleString = "Web Site Developer's Guide for Windows NT"
helloString = "Labeling a graphic with VBScript by "
helloString = helloString & "Sanjaya Hettihewa."
MsgBox helloString, 64, titleString
End Sub
Sub ImageMapGraphic_MouseMove(keyboard,mouse,xPosition,yPosition)
IF (HotSpot(xPosition, yPosition, 2, 5, 70, 41)) THEN
Description.Value = "Main Homepage"
ELSE IF (HotSpot(xPosition, yPosition, 2, 49, 70, 82)) THEN
Description.Value = "Send Feedback"
ELSE IF (HotSpot(xPosition, yPosition, 2, 84, 70, 117)) THEN
Description.Value = "Site Map"
ELSE IF (HotSpot(xPosition, yPosition, 2, 119, 70, 164)) THEN
Description.Value = "Post messages on an online dicussion forum"
ELSE
Description.Value = "No link selected. Please select a link!"
END IF
END IF
END IF
END IF
End Sub
Function HotSpot ( mouseX, mouseY, TopX , TopY, BottomX, BottomY)
HotSpot = (mouseX >= TopX) AND _
(mouseX <= BottomX) AND _
(mouseY >= topY) AND _
(mouseY<=bottomY)
End Function
!-->
</SCRIPT>
</BODY>
</HTML>
VBScript, a subset of Visual Basic, is an easy-to-use scripting language that can be used to create "active" Web pages. It allows Web site developers to create client-side solutions and make a Web site easier and more interesting to navigate.
Now that you've read this book, you should have a good idea of the capabilities of the Internet Information Server and what you can do to make use of them. This is just the tip of the iceberg, however; as IIS grows and matures along with its Windows NT platform, be sure to look for more uses for this near-turnkey Internet server.
There is more to establishing a presence on the Internet than setting up a Web server and using it to publish Web pages. Although IIS is a very powerful Internet information distribution application, numerous other applications can be used with it to set up compelling web sites. If you enjoyed reading this book, you will enjoy reading several upcoming titles from Sams Publishing, such as Web Site Developer's Guide for Windows NT. In addition to discussing various innovative ways of creating content for a web site, this book discusses how to set up more than a dozen Windows NT Internet information distribution applications that can be used to complement information distributed with a Web site.