◎ Vbs Script Programming concise tutorial 15th-response to events

Source: Internet
Author: User

What is an event? In my opinion, the event is like an alarm clock on our mobile phone. When the alarm clock rings, we have to do some specific things. In this case, an event is like an alarm. When a special event occurs while the program is running, the event itself is a message, if you write a script to process events, you need a special process or function to accept and process events. This special process or function is constantly monitored when the program is running to check whether the system has received the corresponding event. Once the event is received, the script responds to the event.

So where did the event come from? Do we need to write events in the script? Under normal circumstances, an event is triggered by a special State in which a program is running. We do not need to write events, but only need to write functions to process events. For example, if we use vbs to create an IE instance, when the IE window is closed, an event called onquit will be triggered.

Does the script naturally accept and process the event? We cannot. When creating an object, we will use the Createobject command of wsh, for example:

Set objie = wscript. Createobject ("internetexplorer. Application", "event _")

Have you noticed? What is the role of an additional parameter? It is called the event receiving end. When the object connected by the script contains an event, if the event called by the object is onbegin, wsh will call an event_onbegin event processing program in the script. Of course, the event receiver is not fixed. if the object is defined as myobj _, the event handler will be myobj_onbegin.

Familiar? In the personalized QQ lecture, the window_onsize (CX, CY) function has appeared. It is actually an event processing program.

Let's take a complete example to see the event handling process:

Set objie = wscript. Createobject ("internetexplorer. Application", "Event _")

Objie. Visible = true

Msgbox "Close the browser window to see the effect! ", Vbsystemmodal

Wscript. Sleep 6000

Msgbox "Disabled now"

Sub event_onquit ()

Msgbox "are you sure you want to close the browser? ", Vbsystemmodal

End sub

This script opens an IE window and asks you to close the IE window. When you close the window, the Event Response Program is automatically called.

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.