VBScript basic teaching 12 using objects in VBScript

Source: Internet
Author: User
Tags object model
Vbscript| Objects | Basic Tutorials

Working with objects

Regardless of whether you are using ActiveX? Control (formerly called an OLE control) or Java? objects, Microsoft Visual Basic scripting Edition and Microsoft? Internet Explorer handles them in the same way. If you are using Internet Explorer and the controls are installed in the ActiveX library, you will see a page made from the following code.

The <OBJECT> tag is used to contain the initial value of the object,

And finally, a simple example of a VBScript page.

Using Microsoft? Internet Explorer can 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 </TITLE>
<script language= "VBScript" >
<!--
Sub Button1_onclick
MsgBox "Mirabile visu."
End Sub
-->
</SCRIPT>
</HEAD>
<BODY>
<H3> a simple home </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.

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 the MsgBox 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.