While you develop Custom ActiveX controls you don’t have to register them in order to use them in the test project. If you want to use a custom’ ActiveX control with a different project, however you must first register it. The process of registering a custom ActiveX control is repeat it here:
1. Choose File. Make control.ocx (control is the name of the custom control) to create the control’s OCX file.
2. Open a DOS Prompt window switch to the folder where the OCX file was saved and issue the command:
C:\windows\system\regsvr32 control.ocx
Replace contro/.ocx with the name of the OCX file you want to reoister.
3. Close the DOSPrompt window.
You’re ready to use the new control in any project even Web pages. In the Visual Basic IDE, the name of the custom control will appear in the Components dialog box (choose Project Components to open this dialog box). The same name will also appear in Front- Page’sActiveX Control Properties dialog box.
The control’s CLASS ID value will be different on your system. Therefore, you can’t use the ALARM.HTM file on the CD as is. You must change the CLASS ID attribute with the value that will be generated on your system
8. Enter the appropriate text and HTML tags on the page save it as
ALARM.HTML and open it with Internet Explore
You should be able to see the Alarm control counting down on the page. Of course, nothing will happen when the alarm times out because you haven’t added any code to the page yet. The script should start the timer as soon as the page is downloaded and when the alarm times out it must take the viewer to another page (the Sybex home page to be exact).
Open the page with a text editor and insert the following script:
<SCRIP! LANGUAGE=’VBScript’>
Sub window_onLoad()
AlarmCtl.AlarmTime – Time + #00:01.00#
Call AlarmCtl.StartTimer()
End Sub
Sub A1anmCt1_TimeOut()
Call window.navigate(.http://www.~ybex.com.)
End Sub
</SCRIPT>
The window _onLoad event is triggered when the page is loaded. In this event you must initialize the control’s properties. Set the Alarm’Iime property to a minute ahead of the current time and start me timer. Youhave already set the Count Down property in the definition of the <OB}ECf> tag. You could have inserted the statement
A1anmCtl.CountDown = True
in the onLoad event’s handler. The AlarmT1U\eproperty can’t be set at design time so it must be set from within the page’s script.
When the Alarm control times out the Alarm_Time Out event is triggered. In this event’s handler we must program the browser to jump to another page with the Window.Navigate method.
The Alarm html page
<HTML)
<HEAD>
.<SCRIPT lANGUAGE·’VBScript’)
Sub window_onLoad()
AlarmCtl.AlarmTime- Time + 100:01.001
Call AlanmCtl.StartTimer()
End Sub
Sub A1anmCtl_TimeOut()
Call w;ndow.nav;gate(.http://www.sybex.com.)
End Sub
</SCRIPT>
<TITLE>A 1arm Demo Page</TITLE>
</HEAD>
<BODY>
<OBJECT id-oAlarmCtl ‘ NAME·’AlanmCtl’
classid-‘c1sid:7282EB2E-B8A9-11CF-B2FB-005348C101FC’
border·’O’ #
width·’120′ height·’33’)
<PARAM NAME-‘CountDown” va1ue-‘True’)
</OB)ECT>
<CENTER)
<HDThe Alarm Page Demo</HD
<FONT SIZE=4>
You will be given 60 seconds to read the important information
on this page and then you’ll be taken to our home page.
<BR>
The little alarm clock at the top of the page will count down every
second and when it reaches zero, your computer will be connected to the
SYBEX home page.
<FONT SIZE = 3>
<HR>
If you are not connected to the Internet, you’ll get an error message
instead.
<HR>
</BODY>
</HTML>
This is the HTML code that produced the page previously-shown in Figure 19.8. The HTML tags are simple and even if you arc not familiar with HTML you can understand the code. To see this control in action follow these steps:
1. Start Internet Explorer.
2. Choose File >: Open. and m the dialog box. locate and open the file Alarrn.html
3. Wait for 60 seconds, and the script will load the Sybex home page.
The Alarm control works nicely in Internet Explorer and we don’t have to adjust it in any way. It behaves just as it does from within Visual Basic. It even exposes its properties and methods and you can program its events
The UINPUT HTML Page
The UINPUT HTML page (shown in Figure 19.9) demonstrates how to use the C Text Box custom ActiveX control on a Web page. Use the process outlined in the Jast section to create the definition of the appropriate <OBJECT> tag with Front- Page and then add the text and HTML tags. The <OBJECT> tag for inserting the CTextBox control is:
<OBJECT id=’CTextBox’
NAME””CTextBoxl’
classid=’clsid:7282EBSA-B8A9-11CF-B2FB-00S348ClOlFC’
border~’O’
WIDTH=’lSO HEIGHT~’19’>
</OBJECT>
The UINPUIHTM page use
the CTextBoxcontrol to
prompt the user for
required and optional data.
This page’s script is simple. It initializes the controls by setting their Mandatory
and Text properties:
Sub wi ndow_onLoadO
CTextBoxl.Mandatory=l
CTextBox2.Mandatory=1
eTe tBox6.Mandatory=1
CTextBoxl.Text~··
CTextBox2.Texta·”
CTextBox3.Text=””
CTextBox4.Text=” .
CTextBox5.Text=”,
CTextBox6.Text=··
End Sub
If these controls are used en a page to collect data from viewers, there will also be a Submit button on the Form. Use the button’s onClick event to make sure the requir d fields have values before submitting the data to the server. On the CD, you’ll also find the LABEL3D.HTM page, which uses the FLXLabel custom control of Chapter 16 to display carved and raised text on the browser’s window. To test the LABEL3D control on a Web pilgC you must first register the control with your sy tern and then replace the control’s CLASSID attribute in the page with the. value that Visual Basic will generate on your system.