To learn more about author Sanjaya Hettihewa, please visit the author's homepage.
ActiveX controls can be automated with VBScript. Certain properties and methods of ActiveX controls are exposed to client-side scripting languages such as VBScript and JavaScript. This exposure allows Web-application developers to combine the capabilities of two or more ActiveX controls to develop sophisticated Web applications.
Properties of ActiveX controls can be modified by VBScript applications to develop interactive Web applications. The application in Listing 25.1 demonstrates how properties of the Calendar object (ActiveX control) can be manipulated to create a perpetual calendar. Users can view the calendar for a certain month when the year and month are provided. The VBScript application in Listing 25.1 can be found in the CD-ROM kit (\Chap-25\Calendar.html) that accompanies this resource library. I suggest that you experiment with the application in the CD-ROM to learn how properties of ActiveX controls are manipulated using VBScript.
1: <!-- 2: © 1996 Sanjaya Hettihewa (http://www.NetInnovation.com/) 3: All Rights Reserved. 4: Permission is hereby given to modify and distribute this code as 5: you wish provided that this block of text remains unchanged. 6: !--> 7: 8: <HTML> 9: <HEAD> 10: <TITLE> 11: Changing Properties Of ActiveX Controls Using VBScript 12: </TITLE> 13: 14: <SCRIPT LANGUAGE="VBScript"> 15: <!-- 16: 17: Sub ChangeDay 18: 19: CalendarObject.Day = InputBox ("Please enter a day", _ 20: "Please enter a day", _ 21: "Please enter a day here", 300, 200) 22: 23: End Sub 24: 25: 26: Sub ChangeMonth 27: 28: CalendarObject.Month = InputBox ("Please enter a month", _ 29: "Please enter a month", _ 30: "Please enter a month here", 300, 200) 31: 32: End Sub 33: 34: Sub ChangeYear 35: 36: CalendarObject.Year = InputBox ("Please enter an year", _ 37: "Please enter an year", _ 38: "Please enter an year here", 300, 200) 39: 40: End Sub 41: 42: --> 43: </SCRIPT> 44: 45: </HEAD> 46: <BODY BGCOLOR=FFFFFF> 47: 48: <p><font color="#0000FF" size="6" face="Comic Sans MS"><strong> 49: The Calendar Object</strong></font></p> 50: 51: <OBJECT ID="CalendarObject" WIDTH=372 HEIGHT=279 52: CLASSID="CLSID:8E27C92B-1264-101C-8A2F-040224009C02"> 53: <PARAM NAME="_Version" VALUE="524288"> 54: <PARAM NAME="_ExtentX" VALUE="9843"> 55: <PARAM NAME="_ExtentY" VALUE="7373"> 56: <PARAM NAME="_StockProps" VALUE="1"> 57: <PARAM NAME="BackColor" VALUE="12632256"> 58: <PARAM NAME="Year" VALUE="1997"> 59: <PARAM NAME="Month" VALUE="1"> 60: <PARAM NAME="Day" VALUE="1"> 61: </OBJECT> 62: 63: <p><font face="Arial"><strong>VBScript can be used to modify the 64: properties of the above ActiveX control. Please select the property 65: you would like to change using one of the command buttons below. 66: </strong></font></p> 67: 68: <form name="InputControls"> 69: <p> 70: <input type="button" name="ChangeDayButton" 71: value="Change Day" onClick="ChangeDay()"> 72: <input type="button" name="ChangeMonthButton" 73: value="Change Month" onClick="ChangeMonth()"> 74: <input type="button" name="ChangeYearButton" 75: value="Change Year" onClick="ChangeYear()"> 76: </p> 77: </form> 78: 79: </BODY> 80: </HTML>
Figure 25.1 illustrates properties of the Calendar object. These properties can be
changed using VBScript, as shown in lines 18, 28, and 36 of Listing 25.1. The following
syntax is used to modify the property of an ActiveX control.
<NameOfObject>.<PropertyNameOfObject> = <NewValueOfProperty>
For example, the following VBScript statement sets the year property of the Calendar object to the year 2000.
CalendarObject.Year = 2000
Figure 25.1. Properties of the Calendar
object (ActiveX control).
Figure 25.2 illustrates the user interface of the VBScript application in Listing
25.1. Notice the command buttons at the bottom of the Web page. These command buttons
are used to change properties of the Calendar object.
Figure 25.2. User interface of the VBScript
application in Listing 25.1.
The year of the Calendar object can be changed by clicking the Change Year button.
The dialog box shown in Figure 25.3 obtains a year from the user. The year 2000 is
specified in the dialog box.
Figure 25.3. Changing the year of the
Calendar object.
Line 36 of Listing 25.1 changes the year of the Calendar object. As shown in Figure
25.4, the year of the Calendar object has been changed to the year 2000.
Figure 25.4. The year of the Calendar
object is changed.
The application in Listing 25.2 is very similar to the one in Listing 25.1. However, Listing 25.2 uses ActiveX controls to modify properties of the Calendar object, as illustrated in Figure 25.5. Users can change properties of the Calendar object using one of the Spin buttons. The VBScript application in Listing 25.2 can be found in the CD-ROM kit (\Chap-25\Link.html) that accompanies this resource library. I suggest that you experiment with the application in the CD-ROM to learn how several ActiveX controls can be linked to Web applications.
<!-- © 1996 Sanjaya Hettihewa (http://www.NetInnovation.com/) All Rights Reserved. Permission is hereby given to modify and distribute this code as you wish provided that this block of text remains unchanged. !--> <HTML> <HEAD> <TITLE> Linking Two Or More ActiveX Controls With VBScript </TITLE> <SCRIPT LANGUAGE="VBScript"> <!-- Sub DaySpinButton_SpinUp CalendarObject.NextDay MonthLabel.Caption = CalendarObject.Month DayLabel.Caption = CalendarObject.Day YearLabel.Caption = CalendarObject.Year End Sub ` -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Sub DaySpinButton_SpinDown CalendarObject.PreviousDay MonthLabel.Caption = CalendarObject.Month DayLabel.Caption = CalendarObject.Day YearLabel.Caption = CalendarObject.Year End Sub ` -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Sub MonthSpinButton_SpinUp CalendarObject.NextMonth MonthLabel.Caption = CalendarObject.Month YearLabel.Caption = CalendarObject.Year DayLabel.Caption = CalendarObject.Day End Sub ` -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Sub MonthSpinButton_SpinDown CalendarObject.PreviousMonth MonthLabel.Caption = CalendarObject.Month YearLabel.Caption = CalendarObject.Year DayLabel.Caption = CalendarObject.Day End Sub ` -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Sub YearSpinButton_SpinUp CalendarObject.NextYear YearLabel.Caption = CalendarObject.Year DayLabel.Caption = CalendarObject.Day MonthLabel.Caption = CalendarObject.Month End Sub ` -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Sub YearSpinButton_SpinDown If (CalendarObject.Year=0) Then MsgBox "I am really sorry but negative years are" & _ " not allowed!" Else CalendarObject.Year = CalendarObject.Year - 1 YearLabel.Caption = YearLabel.Caption - 1 DayLabel.Caption = CalendarObject.Day MonthLabel.Caption = CalendarObject.Month End If End Sub --> </SCRIPT> </HEAD> <BODY BGCOLOR=FFFFFF> <p><font color="#0000FF" size="6" face="Comic Sans MS"> <strong>The Calendar Object</strong></font></p> <OBJECT ID="CalendarObject" WIDTH=372 HEIGHT=279 CLASSID="CLSID:8E27C92B-1264-101C-8A2F-040224009C02"> <PARAM NAME="_Version" VALUE="524288"> <PARAM NAME="_ExtentX" VALUE="9843"> <PARAM NAME="_ExtentY" VALUE="7373"> <PARAM NAME="_StockProps" VALUE="1"> <PARAM NAME="BackColor" VALUE="12632256"> <PARAM NAME="Year" VALUE="1997"> <PARAM NAME="Month" VALUE="1"> <PARAM NAME="Day" VALUE="1"> </OBJECT> <p><font face="Arial"><strong>VBScript can be used to modify the properties of the above ActiveX control. Please select the property you would like to change using one of the ActiveX controls below. </strong></font></p> <TABLE> <TR> <TD> <OBJECT ID="DayLabel" WIDTH=60 HEIGHT=32 CLASSID="CLSID:978C9E23-D4B0-11CE-BF2D-00AA003F40D0"> <PARAM NAME="ForeColor" VALUE="16777215"> <PARAM NAME="BackColor" VALUE="0"> <PARAM NAME="Caption" VALUE="1"> <PARAM NAME="Size" VALUE="1291;635"> <PARAM NAME="FontEffects" VALUE="1073741825"> <PARAM NAME="FontHeight" VALUE="280"> <PARAM NAME="FontCharSet" VALUE="0"> <PARAM NAME="FontPitchAndFamily" VALUE="2"> <PARAM NAME="ParagraphAlign" VALUE="3"> <PARAM NAME="FontWeight" VALUE="700"> </OBJECT> <OBJECT ID="DaySpinButton" WIDTH=16 HEIGHT=32 CLASSID="CLSID:79176FB0-B7F2-11CE-97EF-00AA006D2776"> <PARAM NAME="Size" VALUE="423;846"> </OBJECT> </TD> <TD> <OBJECT ID="MonthLabel" WIDTH=60 HEIGHT=32 CLASSID="CLSID:978C9E23-D4B0-11CE-BF2D-00AA003F40D0"> <PARAM NAME="ForeColor" VALUE="16777215"> <PARAM NAME="BackColor" VALUE="0"> <PARAM NAME="Caption" VALUE="1"> <PARAM NAME="Size" VALUE="1291;635"> <PARAM NAME="FontEffects" VALUE="1073741825"> <PARAM NAME="FontHeight" VALUE="280"> <PARAM NAME="FontCharSet" VALUE="0"> <PARAM NAME="FontPitchAndFamily" VALUE="2"> <PARAM NAME="ParagraphAlign" VALUE="3"> <PARAM NAME="FontWeight" VALUE="700"> </OBJECT> <OBJECT ID="MonthSpinButton" WIDTH=16 HEIGHT=32 CLASSID="CLSID:79176FB0-B7F2-11CE-97EF-00AA006D2776"> <PARAM NAME="Size" VALUE="423;846"> </OBJECT> </TD> <TD> <OBJECT ID="YearLabel" WIDTH=60 HEIGHT=32 CLASSID="CLSID:978C9E23-D4B0-11CE-BF2D-00AA003F40D0"> <PARAM NAME="ForeColor" VALUE="16777215"> <PARAM NAME="BackColor" VALUE="0"> <PARAM NAME="Caption" VALUE="1997"> <PARAM NAME="Size" VALUE="1291;635"> <PARAM NAME="FontEffects" VALUE="1073741825"> <PARAM NAME="FontHeight" VALUE="280"> <PARAM NAME="FontCharSet" VALUE="0"> <PARAM NAME="FontPitchAndFamily" VALUE="2"> <PARAM NAME="ParagraphAlign" VALUE="3"> <PARAM NAME="FontWeight" VALUE="700"> </OBJECT> <OBJECT ID="YearSpinButton" WIDTH=16 HEIGHT=32 CLASSID="CLSID:79176FB0-B7F2-11CE-97EF-00AA006D2776"> <PARAM NAME="Size" VALUE="423;846"> </OBJECT> </TD> </TR> </TABLE> </BODY> </HTML>
Figure 25.5. User interface of the
VBScript application in Listing 25.2.
The Spin buttons can change the values of the Calendar control, as shown in Figure
25.6. All three Spin buttons function in the same way. For example, when the YearSpinButton
is moved up, the VBScript subroutine defined in lines 53-58 (YearSpinButton_SpinUp)
of Listing 25.2 is triggered. The YearSpinButton_SpinUp subroutine increments the
current year of the Calendar object using the statement CalendarObject.NextYear.
The new year of the Calendar object is then assigned to the YearLabel object using
the statement YearLabel.Caption = CalendarObject.Year.
Figure 25.6. Values of the Calendar object can be changed using the Spin buttons.
The application in Listing 25.1 demonstrates how to change properties of an ActiveX control, and the application in Listing 25.2 demonstrates how to link two or more ActiveX controls together with VBScript. These techniques can be used to develop sophisticated VBScript applications. Because Java applets are also ActiveX controls, VBScript can be used to link Java applets with Web-application components developed using other programming languages, such as Visual Basic and C++.
VBScript can be used to automate and modify the properties of ActiveX controls. ActiveX, along with various aspects of the VBScript language covered in Chapters 13-23, can be used to develop interactive and multimedia-rich Web applications.
© Copyright, Macmillan Computer Publishing. All rights reserved.