A simple example of a VBScript page
A simple page
Use Microsoft Internet Explorer to view pages made with the following HTML code. If you click a button on the page, you can see the results of VBScript running.
<HTML><HEAD><TITLE>
A simple home page </TITLE>
<SCRIPT LANGUAGE="VBScript">
<!--
Sub Button1_onClick
MsgBox "Hello, world!"
End Sub
-->
</SCRIPT>
</HEAD>
<BODY>
<H3>
A simple first </H3><HR>
<FORM><INPUT NAME="Button1" TYPE="BUTTON" VALUE="
click here"></FORM>
</BODY>
</HTML>
The result is a bit simple: a dialog box displays a Latin phrase (meaning "looks very beautiful"). However, this code actually does a lot of things.
When Internet Explorer reads a page, locate the <SCRIPT> tag, identify the VBScript code, and save the code. When you click the button, Internet Explorer makes the button connect to the code and runs the procedure.
The Sub procedure in the <SCRIPT> tag is an event procedure. A procedure name consists of two parts: a button name, Button1 (obtained from the Name property in the <INPUT> tag), and an event name, or OnClick. The two parts are connected by an underscore (_). When you click the button, Internet Explorer looks for and runs the appropriate event procedure, Button1_onclick.
Internet Explorer defines the events that are available for form controls in the Internet Explorer scripting Object Model document, which can be found on the Microsoft (R) Web site (http:// www.microsoft.com).
The page can also use a combination of controls and procedures. VBScript and the form show some simple interactions between controls.
Other ways to attach code to an event
The above method may be the simplest and most commonly used, but there are two other ways to attach VBScript code to the event. One way is to add a shorter internal code to the markup that defines the control. For example, when you click a button, the following <INPUT> tag performs the same actions as the previous example:
<INPUT NAME="Button1" TYPE="BUTTON" VALUE="
Click here" onClick='MsgBox "Mirabile visu."'>
Note that the function call is enclosed in single quotes, and the string of theMsgBox function is enclosed in double quotes. Just use a colon (:) Separate statements, you can use more than one statement.
Another way is to specify specific controls and events in the <SCRIPT> tag:
<SCRIPT LANGUAGE="VBScript" EVENT="onClick" FOR="Button1"><!-- MsgBox "Mirabile visu."--></SCRIPT>
Because the <SCRIPT> tag specifies events and controls, you do not need to use sub and end sub statements again.