VBS TUTORIAL: A simple sample of the VBScript page _vbs

Source: Internet
Author: User
Tags object model

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.