A Simple VBScript Page - Microsoft® Visual Basic® Scripting Edition

> ### A Simple VBScript Page

> ##### A Simple Page

> > With Microsoft Internet Explorer 3.0, you can view the page produced by the HTML code below. If you clicked the button on the page, you'd see Microsoft Visual Basic Scripting Edition in action.

> >     <HTML>
> >     <HEAD><TITLE>A Simple First Page</TITLE>
> >     <SCRIPT LANGUAGE="VBScript">
> >     <!--
> >     Sub Button1_OnClick
> >             MsgBox "Mirabile visu."
> >     End Sub
> >     -->
> >     </SCRIPT>
> >     </HEAD>
> >     <BODY>
> >     <H3>A Simple First Page</H3><HR>
> >     <FORM><INPUT NAME="Button1" TYPE="BUTTON" VALUE="Click Here"></FORM>
> >     </BODY>
> >     </HTML>

> > The result is a little underwhelming: you see a dialog box with a phrase in it (Latin for "Wonderful to behold"). However, there's quite a bit going on.

> > When Internet Explorer reads the page, it finds the <SCRIPT> tags, recognizes there is a piece of VBScript code, and saves the code. Then when you click the button, Internet Explorer makes the connection between the button and the code, and runs the procedure.

> > The Sub procedure in the <SCRIPT> tags is known as an event procedure. You'll notice that there are two parts to the procedure name: the name of the button, Button1 (from the NAME attribute in the <INPUT> tag), and an event name, OnClick; the two are joined together by an underscore. Anytime the button is clicked, Internet Explorer looks for and runs the corresponding event procedure, Button1_OnClick.

> > Internet Explorer 3.0 defines the events available for form controls in the Scripting Object Model documentation.

> > Pages can use combinations of controls and procedures, too. The next page, VBScript and Forms, shows some simple interactions among controls.

> ##### Other Ways to Attach Code to Events

> > You can attach VBScript code to events in two other ways, though the way you've already seen is probably the most general and simple.

> > Internet Explorer 3.0 allows you to add short sections of inline code in the tag defining the control. For example, the following <INPUT> tag does precisely the same action as the previous code example when you click the button:

> >     <INPUT NAME="Button1" TYPE="BUTTON"
> >            VALUE="Click Here" OnClick='MsgBox "Mirabile visu."'>

> > Notice that the function call itself is in single quotes and the string for the MsgBox function is in double quotes. You can use multiple statements as long as you separate the statements with colons (:).

> > You can also write a <SCRIPT> tag so that it applies only to a particular event for a specific control:

> >     <SCRIPT LANGUAGE="VBScript" EVENT="OnClick" FOR="Button1">
> >     <!--
> >         MsgBox "Mirabile visu."
> >     -->
> >     </SCRIPT>

> > Here, since the <SCRIPT> tag already specifies the event and the control, you don't use the Sub and End Sub statements.

> © 1996 by Microsoft Corporation.