Writing Event Procedures

Using Properties and Methods of Controls

Accessing properties and invoking methods are the most common tasks performed by the event procedures of objects.

Accessing Properties

Syntax To set the value of a property, use the following syntax:
 Object.  Property = Value  

Syntax

To retrieve the value of a property, use this syntax:
  ReturnValue  = Object.  Property  

Example

This example reads the date selected in a Calendar control, computes the shipping cost to deliver on that date, and then displays the calculated cost in a standard HTML text box:
 Sub ShipDate_Click() Dim shiptime shiptime = ShipDate.Value - Date If shiptime < 0 Then MsgBox "Can't ship before today" ElseIf shiptime < 5 Then frmShip.txtCost.Value = 12 Else frmShip.txtCost.Value = 8 End If End Sub 

Invoking Methods

Syntax Methods in script are invoked in the same way as in Visual Basic; that is, by using the following syntax:
  [Call]  Object.  Method  

Example

This example calls the Today method of the Calendar control when a user clicks the Reset button:
 Sub Reset_OnClick() call ShipDate.Today() End Sub 

The Call keyword is optional. If you specify Call , you must enclose the arguments in parentheses.

Lesson Summary

Microsoft VBScript is the Internet-optimized version of Microsoft Visual Basic. The syntax of VBScript is identical to that of Visual Basic for Applications. However, VBScript is designed to download quickly over the Internet. VBScript supports most inherent Visual Basic functions, such as Msgbox , Date , and IsNumeric .

You can use VBScript to set properties and methods of ActiveX controls and Java applets that are contained within an HTML page. VBScript features sub procedures and function procedures, and it supports the use of variables such as data types, arrays, scope, and constants. VBScript also supports most of the Visual Basic for Applications structures for controlling program flow. Just as in traditional Visual Basic applications, you can include error handling scripts on a Web page. Using script, you can also control objects and respond to events.



Microsoft Windows Architecture Training
Microsoft Windows Architecture for Developers Training Kit
ISBN: B00007FY9D
EAN: N/A
Year: 1998
Pages: 324

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net