Dynamic HTML (DHTML) Scriptlets
You can create custom reusable objects for Web pages by using DHTML scriptlets. DHTML scriptlets are Web pages in which script procedures have been written according to certain conventions so that these procedures behave like methods and properties of the scriptlet. Scriptlets are supported in Internet Explorer version 4.0 and later. You can build scriptlets in either Microsoft Visual Basic Scripting Edition (VBScript) or Microsoft JScript.
Scriptlets can be script only, or they can have a user interface component in addition to script. You can include a scriptlet in the HTML for other pages in order to add the functionality that the scriptlet provides to those pages. By building scriptlets, you can componentize the process of developing Web pages in much the same way that you componentize solutions with custom objects in VBA.
For example, the scriptlet included in the ODETools\V9\Samples\OPG\Samples\CH03 subfolder on the Office 2000 Developer CD-ROM, Scriptlet.htm, includes code that returns the current month name, day of month, and year. The file ScriptGoodFormatting.htm, also in the ODETools\V9\Samples\OPG\Samples\CH03 subfolder, refers to this scriptlet in order to display a digital clock on the Web page.
You refer to a scriptlet in an <OBJECT> tag in the HTML code for the page in which you want to use it. The following HTML code, taken from ScriptGoodFormatting.htm, shows how to refer to the Scriptlet.htm sample file. Note that the DATA attribute contains the name of the scriptlet file, Scriptlet.htm; this is comparable to the name of a class in VBA. The name for the scriptlet, as it is referred to within the script in ScriptGoodFormatting.htm, is
scrltDateCode; this name is comparable to the variable that you use to represent an instance of a class in VBA.
<OBJECT ID="scrltDateCode" STYLE= "position:absolute; width:0; height:0;" type="text/x-scriptlet" data="Scriptlet.htm"> </OBJECT>
The scriptlet file itself, Scriptlet.htm, contains script procedures that behave like methods and properties. The following procedure defines the GetYear property for the scriptlet:
Function public_get_GetYear() ' Return the current year. public_get_GetYear = Year(Date()) End Function
Once the scriptlet has been included in a Web page by using the <OBJECT> tag, script in that Web page can call methods and properties of the scriptlet. For example, the following script fragment from ScriptGoodFormatting.htm returns the value of the scriptlet's GetYear property and stores it in a variable.
Dim strCurrentYear strCurrentYear = scrltDateCode.GetYear