Chapter 14

VB Script and ActiveX Controls


CONTENTS

VB Script and ActiveX are two relatively new technologies from Microsoft. They are similar to JavaScript and Java, respectively, in that the former are scripting languages for Web browsers (primarily), and the latter are ways of adding increased functionality to Web browsers. Together, they provide a framework that can be used to make Microsoft's Internet Explorer and other compatible Web browsers, into very capable tools for working over the Internet, as well as an Intranet.

In this chapter, you will learn:

What Is Visual Basic Script?

Like the JavaScript language, first introduced by Netscape and fully supported by Microsoft in Internet Explorer 3, the Visual Basic Script (VB Script) scripting language enables you to embed commands into an HTML document. When an Internet Explorer 3 user downloads the page, your VB Script commands are loaded by the Web browser along with the rest of the document and are run in response to any of a series of events. Again, like JavaScript, VB Script is an interpreted language; Internet Explorer 3 interprets the VB Script commands when they are loaded and run. They do not need to be compiled into executable form by the Web author who uses them.

VB Script is a fast and flexible subset of Microsoft's Visual Basic and Visual Basic for Applications languages. It is designed to be easy to program in and for adding active content to HTML documents quickly. The language elements are mainly ones that will be familiar to anyone who has programmed in just about any language, such as If...Then...Else blocks, Do, While, and For...Next loops, along with a typical assortment of operators and built-in functions. This chapter attempts to give you an overview of the VB Script language and show you examples of how to use it to add greater interaction to your Web pages.

Why Use a Scripting Language?

HTML provides a good deal of flexibility to page authors, but HTML by itself is static; once written, HTML documents can't interact with the user other than by presenting hyperlinks. Creative use of CGI scripts (which run on Web servers) has made it possible to create more interesting and effective interactive sites, but some applications really demand programs or scripts that are executed by the client.

One of the reasons VB Script was developed was to provide Web authors a way to write small scripts that would execute on the users' browsers instead of on the server. For example, an application that collects data from a form and then posts it to the server can validate the data for completeness and correctness before sending it to the server. This can greatly improve the performance of the browsing session, because users don't have to send data to the server until it's been verified as correct. It also helps to reduce network bandwidth, either over the Internet or an Intranet, by performing data checks locally and not sending it to a server until it has been verified to be correct. The following are some other potential applications for VB Script:

What Can VB Script Do?

VB Script provides a fairly complete set of built-in functions and commands, enabling you to perform math calculations, play sounds, open up new windows and new URLs, and access and verify user input to your Web forms.

Code to perform these actions can be embedded in a page and executed when the page is loaded; you can also write functions that contain code that's triggered by events you specify. For example, you can write a VB Script method that is called when the user clicks the Submit button of a form, or one that is activated when the user clicks a hyperlink on the active page.

VB Script can also set the attributes, or properties, of OLE controls or Java applets running in the browser. This way, you can easily change the behavior of plug-ins or other objects without having to delve into their innards. For example, your VB Script code could automatically start playing an embedded .AVI file when the user clicks a button.

How Does VB Script Look in an HTML Document?

VB Script commands are embedded in your HTML documents, either directly or via a URL that tells the browser which scripts to load, just as with JavaScript (and other scripting languages). Embedded VB Scripts are enclosed in the HTML container tag <SCRIPT>...</SCRIPT>.

The <SCRIPT> element takes two attributes: LANGUAGE, which specifies the scripting language to use when evaluating the script, and SRC, which specifies a URL from which the script can be loaded. The LANGUAGE attribute is always required, unless the SRC attribute's URL specifies a language. LANGUAGE and SRC can both be used, too. For VB Script, the scripting language is defined as LANGUAGE="VBS". Some examples of valid SCRIPT tags are as follows:

<SCRIPT LANGUAGE="VBS">...</SCRIPT>
<SCRIPT SRC="http://www.rpi.edu/~odonnj/scripts/common.VBS">...</SCRIPT>
<SCRIPT LANGUAGE="VBS" SRC="http://www.rpi.edu/~odonnj/scripts/common">...</SCRIPT>

VB Script resembles JavaScript and many other computer languages you may be familiar with. It bears the closest resemblance, as you might imagine, to Visual Basic and Visual Basic for Applications because it is a subset of these two languages. The following are some of the simple rules you need to follow for structuring VB Scripts:

VB Script Programming Hints

You should keep in mind a few points when programming with VB Script. These hints ease your learning process and make your HTML documents that include VB Scripts more compatible with a wider range of Web browsers.

Hiding Your Scripts

Because VB Script is a new product and is currently supported only by Internet Explorer 3-though Oracle, Spyglass, NetManage, and other companies plan to license the technology for future versions of their Web browsers-you'll probably be designing pages that will be viewed by Web browsers that don't support it. To keep those browsers from misinterpreting your VB Script, wrap your scripts as follows:

<SCRIPT LANGUAGE="VBS">
<!-- This line opens an HTML comment
VB Script commands...
<!-- This line opens and closes an HTML comment -->
</SCRIPT>

The opening <!-- comment causes Web browsers that do not support VB Script to disregard all text they encounter until they find a matching -->, so they don't display your script. Make sure that your <SCRIPT>...</SCRIPT> container elements are outside the comments, though; otherwise, Internet Explorer 3 ignores the whole script.

Comments

Including comments in your programs to explain what they do is usually good practice; VB Script is no exception. The VB Script interpreter ignores any text marked as a comment, so don't be shy about including them. Comments in VB Script are set off using the REM statement (short for remark) or by using a single quotation mark (') character. Any text following the REM or single quotation mark, until the end of the line, is ignored. To include a comment on the same line as another VB Script statement, you can use either REM or a single quotation mark. However, if you use REM, you must separate the statement from the REM with a colon (the VB Script multiple-command-per-line separator).

VB Script, Visual Basic, and Visual Basic for Applications

As mentioned previously, VB Script is a subset of the Visual Basic and Visual Basic for Applications languages. If you are familiar with either of these two languages, you will find programming in VB Script very easy. Just as Visual Basic was meant to make the creation of Windows programs easier and more accessible, and Visual Basic for Applications was meant to do the same for Microsoft Office applications, VB Script is meant to give an easy-to-learn, yet powerful, means for adding interactivity and increased functionality to Web pages.

The VB Script Language

VB Script was designed as a subset of Visual Basic and Visual Basic for Applications. As a subset, it doesn't have as much functionality but was intended to provide a quicker and simpler language for enhancing Web pages and servers. This section discusses some of the building blocks of VB Script and how they are combined into VB Script programs.

Using Identifiers

An identifier is just a unique name that VB Script uses to identify a variable, method, or object in your program. As with other programming languages, VB Script imposes some rules on what names you can use. All VB Script names must start with an alphabetic character and can contain both upper- and lowercase letters and the digits 0 through 9. They can be as long as 255 characters, though you probably don't want to go much over 32 or so.

Unlike JavaScript, which supports two different ways for you to represent values in your scripts, literals and variables, VB Script really has only variables. The difference in VB Script, then, is one of usage. You can include literals-constant values-in your VB Script programs by setting a variable equal to a value and not changing it. We will continue to refer to literals and variables as distinct entities, though they are interchangeable.

Literals and variables in VB Script are all type variant, which means that they can contain any type of data that VB Script supports. It is usually a good idea to use a given variable for one type and explicitly convert its value to another type, as necessary. The following are some of the types of data that VB Script supports:

Objects, Properties, Methods, and Events

Before you proceed further, you should take some time to review some terminology that may or may not be familiar to you. VB Script follows much the same object model as JavaScript, and uses many of the same terms. In VB Script, just as in JavaScript-and in any object-oriented language for that matter-an object is a collection of data and functions that have been grouped together. An object's data is known as its properties, and its functions are known as its methods. An event is a condition to which an object can respond, such as a mouse click or other user input. The VB Script programs that you write make use of properties and methods of objects, both those that you create and objects provided by Internet Explorer 3, its plug-ins, Java applets, and the like.

TIP
Here's a simple guideline: An object's properties are the information it knows, its methods are how it can act on that information, and events are what it responds to.

Using Built-In Objects and Functions

Individual VB Script elements are objects; for example, literals and variables are objects of type variant, which can be used to hold data of many different types. These objects also have associated methods, ways of acting on the different data types. VB Script also enables you to access a set of useful objects that represent the Internet Explorer 3 browser, the currently displayed page, and other elements of the browsing session.

You access objects by specifying their names. For example, the active document object is named document. To use document's properties or methods, you add a period and the name of the method or property you want. For example, document.title is the title property of the document object.

Using Properties

Every object has properties-even literals. To access a property, just use the object name followed by a period and the property name. To get the length of a string object named address, you can write the following:

address.length

You get back an integer that equals the number of characters in the string. If the object you're using has properties that can be modified, you can change them in the same way. To set the color property of a house object, just write the following:

house.color = "blue"

You can also create new properties for an object just by naming them. For example, say you define a class called customer for one of your pages. You can add new properties to the customer object as follows:

customer.name = "Joe Smith"
customer.address = "123 Elm Street"
customer.zip = "90210"

Finally, knowing that an object's methods are just properties is important, so you can easily add new properties to an object by writing your own function and creating a new object property using your own function name. If you want to add a Bill method to your customer object, you can write a function named BillCustomer and set the object's property as follows:

customer.Bill = BillCustomer;

To call the new method, you just write the following:

customer.Bill()

HTML Elements Have Properties, Too

Internet Explorer 3 provides properties for HTML forms and some types of form fields. VB Script is especially valuable for writing scripts that check or change data in forms. Internet Explorer 3's properties enable you to get and set the form elements' data, as well as specify actions to be taken when something happens to the form element (as when the user clicks in a text field or moves to another field).

Programming with VB Script

As you've learned in the preceding sections, VB Script has a lot to offer Web page authors. It's not as flexible as C or C++, but it's quick and simple. But, since it is easily embedded in your Web pages, adding interactivity with a little VB Script is easy. This section covers more details about VB Script programming, including a detailed explanation of the language's features.

A full description of the VB Script language would take much more space than this one chapter. Instead, you can read about the highlights of the language later. For a complete description of the VB Script language, go to the Microsoft VB Script Web site at http://www.microsoft.com/vbscript/.

Variables and Literals

VB Script variables are all of the type variant, which means that they can be used for any of the supported data types. Constants in VB Script, called literals, are similar to variables and can also be of any type. In fact, VB Script doesn't really have any "constants" in the usual sense of the word, since VB Script treats literals the same as variables. The difference lies in how the programmer uses them. VB Script variables can hold boolean data, one-, two-, or four-byte integers, four-or eight-byte real numbers, dates, strings, and a few specialized types such as objects and error numbers.

Expressions

An expression is anything that can be evaluated to get a single value. Expressions can contain string or numeric literals, variables, operators, and other expressions, and they can range from simple to quite complex. For example, the following is an expression that uses the assignment operator (more on operators in the next section) to assign the result 3.14159 to the variable sngPi:

sngPi = 3.14159

By contrast, the following is a more complex expression whose final value depends on the values of the two Boolean variables blnQuit and blnComplete:

(blnQuit = TRUE) And (blnComplete = FALSE)

Operators

Operators do just what their name suggests; they operate on variables or literals. The items that an operator acts on are called its operands. Operators come in the two following types:

VB Script supports the = assignment operator, math operators such as +, -, and *, comparison operators such as < and >=, logical operators such as And and Or, and the string concatenation operator &.

Controlling Your VB Scripts

Sometimes the scripts that you write are very simple and execute the same way each time they are loaded-a script to display a graphic animation, for instance. However, in order to write a script that will perform different functions depending on different user inputs or other conditions, you need to add a little more sophistication. VB Script provides statements and loops for controlling the execution of your programs based on a variety of inputs.

If you are familiar with just about any other computer language, you will recognize most of the control structures used in VB Script. They include the following types:

if (sngX> sngPi) then
    blnTest = TRUE
    intCount = intCount + 1
else
    blnTest = FALSE
    intCount = 0
end if
intCount = 1
do
    document.write "Count is " & CStr(intCount) & "<BR>"
    intCount = intCount + 1
until (intCount = 101)
NOTE
Again, we've barely even scratched the surface of VB Script-the language itself, what it can do, and how it interacts with the Web browser and user. For a complete reference on using VB Script, see the VB Script Web site at http://www.microsoft.com/vbscript.

VB Script Examples

Microsoft maintains a listing of sites making use of VB Scripts. This list is a great way to find out what is really possible using the VB Script techniques. You can access this list through the VB Script Web site at http://www.microsoft.com/vbscript/. Another good list of VB Script sites is given at the Visual Basic Pro Web site located at http://www.inquiry.com/techtips/thevbpro/.

Displaying Real-Time Data Using VB Scripts

One of the sites listed on the Microsoft VB Script Site list shows a good example of what can be done by combining VB Script and JavaScripts is the Investor's Edge Web site, which uses them to show real-time financial information. Investor's Edge is located at http://www.investorsedge.com/.

Interacting with Objects

This example shows an example of how to use VB Script to manipulate another Web browser object, the ActiveX Label Control (you'll learn more about ActiveX Controls below). The label control enables the Web author to place text on the Web page, select the text, font, size, and an arbitrary angle of rotation. One of the exciting things about the label control is that it can be manipulated in real time, and produce a variety of automated or user-controlled effects.

In the example shown below, text is placed on the Web page using the label control, and form input is used to enable the user to change the text used and the angle at which it is displayed. Figure 14.1 shows the default configuration of the label, and figure 14.2 shows it after the text and the rotation angle has been changed. This is a good example in that it shows interaction of VB Script, HTML forms, and an ActiveX Control.

Figure 14.1 : The ActiveX Label Control allows arbitrary text to be displayed by the Web author in the size, font, position, and orientation desired.

Figure 14.2 : VB Script's ability to manipulate Web browser objects allows the label parameters to be changed dynamically.

Listing 14.1 shows the code used to produce this example. Some things to note about the example are the following:


Listing 14.1  14LST06.HTM  VB Script Can Interact with Objects
<HTML>
<HEAD>
<OBJECT
     classid="clsid:{99B42120-6EC7-11CF-A6C7-00AA00A47DD2}"
     id=lblActiveLbl
     width=250
     height=250
     align=left
     hspace=20
     vspace=0
>
<PARAM NAME="_extentX" VALUE="150">
<PARAM NAME="_extentY" VALUE="700">
<PARAM NAME="Angle" VALUE="90">
<PARAM NAME="Alignment" VALUE="2">
<PARAM NAME="BackStyle" VALUE="0">
<PARAM NAME="Caption" VALUE="A Simple Desultory Label">
<PARAM NAME="FontName" VALUE="Arial">
<PARAM NAME="FontSize" VALUE="20">
<PARAM NAME="FontBold" VALUE="1">
<PARAM NAME="FrColor" VALUE="0">
</OBJECT>

<SCRIPT LANGUAGE="VBS">
<!--
Sub cmdChangeIt_onClick
     Dim TheForm
     Set TheForm = Document.LabelControls
     lblActiveLbl.Caption = TheForm.txtNewText.Value
End Sub
Sub cmdRotateP_onClick
     Dim TheForm
     Set TheForm = Document.LabelControls
     lblActiveLbl.Angle = lblActiveLbl.Angle + 5
      Document.LabelControls.sngAngle.Value = lblActiveLbl.Angle
End Sub
Sub cmdRotateM_onClick
     Dim TheForm
     Set TheForm = Document.LabelControls
     lblActiveLbl.Angle = lblActiveLbl.Angle - 5
      Document.LabelControls.sngAngle.Value = lblActiveLbl.Angle
End Sub
-->
</SCRIPT>

<TITLE>VB Script and Object Manipulation</TITLE>
</HEAD>
<BODY>

<FORM NAME="LabelControls">
<TABLE>
<TR><TD><INPUT TYPE="TEXT" NAME="txtNewText" SIZE=25></TD>
    <TD><INPUT TYPE="BUTTON" NAME="cmdChangeIt" VALUE="Change Text">
    </TD></TR>
<TR><TD><INPUT TYPE="TEXT" NAME="sngAngle" SIZE=5></TD>
    <TD><INPUT TYPE="BUTTON" NAME="cmdRotateP" VALUE="Rotate Label + 5">
    </TD></TR>
<TR><TD></TD>
    <TD><INPUT TYPE="BUTTON" NAME="cmdRotateM" VALUE="Rotate Label - 5">
    </TD></TR>
</TABLE>
</FORM>

<SCRIPT LANGUAGE="VBS">
<!--
Document.LabelControls.sngAngle.Value = lblActiveLbl.Angle
-->
</SCRIPT>

</BODY>
</HTML>

Introducing ActiveX Controls

Microsoft's Object Linking and Embedding technology (OLE) has been one of the most significant breakthroughs in application development thus far. OLE itself is derived from the Component Object Model (COM) technology, which is a standard and defines how OLE components, or objects, interact with each other. Fortunately, you do not have to understand COM technology to utilize OLE functionality.

When application development was still in the 16-bit phase Microsoft's OLE controls were in the .VBX format (Visual Basic Control). Since the 32-bit development boom, this has been replaced with its 32-bit counterpart-the .OCX format. Not long after its introduction, when Microsoft really joined the Internet race, .OCX file formats were taken to a new level-ActiveX controls.

ActiveX/OCX-the Difference

Simply put, ActiveX controls are OLE components that can be inserted into Web pages. Therefore, ActiveX controls are in fact .OCX files that have been extended to Internet use. Currently, the new MS Internet Explorer fully supports ActiveX controls, and documents. With the help of a plug-in (NCompass), Netscape also can offer support.

ActiveX versus Java

Like a Java applet, an ActiveX control runs on the client computer within the browser. ActiveX gains its advantage, however, because it's language independent, which means developers can develop in any language supporting the COM technology. ActiveX is also able to support a wider range of GUI components than Java can currently offer.

Java has the advantage of being platform independent, while ActiveX controls can run only on client computers that support OLE 2.0. Java is also more secure; ActiveX controls are free to perform all types of functions on the client machine, while Java implements strict security guidelines for their programs.

How Can You Use ActiveX Controls on the Intranet?

Until the introduction of ActiveX, CGI scripts were used for most of the user interaction on the Internet. This worked fine and there didn't seem to be many complaints at the beginning. However, CGI had its limits. CGI programs ran on the server and would tie up server resources; they also proved to be rather slow, and error prone. CGI scripts were written in languages like Perl, which responded to HTML form events, and were limited to the events passed by the HTML form. Figure 14.3 shows an HTML form with buttons that send events (called actions) to a CGI script.

Figure 14.3 : An HTML form with buttons that will send an event (called actions) to a script on the Web server.

NOTE
CGI stands for Common Gateway Interface, and is a protocol that defines the way a Server script communicates with a client program. CGI is not a programming language, and therefore CGI scripts can be written in virtually any language that supports input/output streams. Perl is the most commonly used language for CGI programming because of its simplicity.

ActiveX can offer a much richer set of components than CGI. With ActiveX, you can replace simple HTML forms with interactive spreadsheets, smarter buttons, Dialog boxes, and basically any OLE control you can think of. In addition to this, you can also add document objects from your favorite applications, such as MS Word, MS PowerPoint, and so on.

ActiveX Requirements

There are certain requirements that should be addressed before you delve into the world of ActiveX development. Questions that you should ask yourself before you begin are:

This section addresses these questions.

The Client-Server Environment

ActiveX supports the client-server environment in this way: A client requests an HTML page through his/her browser from the Web server. If the HTML page contains an ActiveX control, the control is downloaded to the client side if it does not already exist. The ActiveX control, once downloaded, runs entirely on the client computer. Since all Intranet environments are also client-server environments, you need not worry about having to implement client-server architecture.

Server Requirements

A server doesn't need much to be able to serve ActiveX controls to clients. MIME types must be set so that the client program knows what type of data it will be receiving, and how to handle it. Setting the MIME types differs for each type of server. The MIME type for an ActiveX control is application/x-oleobject. See the user's manual of your Web Server to set this value correctly.

NOTE
MIME stands for Multipurpose Internet Mail Extension, and does more than handle the way mail is sent. MIME is used to define documents on a Web server so that client programs, such as browsers, can use these definitions to determine what application should be executed to display the document. These applications usually come in the form of a plug-in or helper application.

The MIME settings for ActiveX controls will be discussed again later in this chapter.

Client Requirements

Because ActiveX controls are downloaded from the server, and then run on the client machine, there are certain requirements that need to be met on the client machine for the control to be executed.

Required .DLLs

All ActiveX controls require the MFC40.dll in order to function. If the client computer does not have this control, the requested ActiveX control can't be displayed. This means that the .DLL must be downloaded and placed in the Windows\System subdirectory of the client before the ActiveX control. It may be a good idea to provide a link to download this .DLL before giving the user access to the Web page containing the ActiveX control. Any other .DLLs that are used by the control also need to be on the client computer. For ActiveX documents, all clients being served need to have the viewer files for these documents in order to view them. This means that if you were serving MS Word documents, your clients must have either the entire MS Word application, or at least the viewer files. Viewer files for the MS Application suite are available at http://www.microsoft.com/msoffice/msword/internet/viewer/.

Operating System Requirements

Unlike Java, ActiveX is not platform independent. The clients that you serve must have an operating system that supports the controls you develop or the documents you create.

Supported Browsers

Currently, ActiveX controls and documents are supported by the MS Internet Explorer version 3.0. At the time that this chapter was written, there was not a final version of MS Explorer, but a prereleased version is available with the ActiveX SDK. Unbeknownst to many, Netscape can also display ActiveX controls. The only difference is that Netscape requires a plug-in to do so. I found a great plug-in that supports ActiveX controls. The plug-in is called NCompass and is available at http://www.ncompasslabs.com/. NCompass enables you to display ActiveX controls and documents in the Netscape browser Window. It also provides the ability to download multiple .OCX files and dependent .DLLs together with the main control.

Using ActiveX Documents (or Document Objects) on the Intranet

Now that all the theory is over, it's time to put what you learned about ActiveX into action. In this section you learn how to add ActiveX documents (also called doc objects) to the HTML pages that you serve on your corporate Intranet.

Choosing a Suite of Applications

The first step to serving ActiveX documents is to choose a suite of applications to serve. Currently, only MS Office documents are supported as ActiveX documents, so this is the suite of applications discussed throughout this chapter. Once the application suite is chosen, the next step is to provide a means for your clients to view these applications. This means providing access for clients to download the viewer files, or notifying browsers with an HTML page prior to the page containing the document that they need to have the MS Office package ( or one of its applications) to view the following ActiveX documents. Viewers that already have these files ignore this warning and proceed to viewing the files. In order to view these files as ActiveX documents, the servers and clients need to have the correct MIME types configured for serving and receiving them. This is done automatically by the NCompass plug-in for Netscape, or by MS Explorer 3.0. Once this is done, ActiveX documents are available for viewing through the browser window.

Embedding Documents into Your Web Page

Embedding a document into your Web page is as simple as providing a direct link to the document using the HREF tag. For example, if you want to provide a link to a MS Word document, use:

<A HREF="http://www.mysite.com/documents/mydoc.doc>

and the user sees the specified Word document, appear in their browser window. An example of a MS Word document in a Netscape Browser (made possible by the NCompass plug-in) is shown in figure 14.4.

Figure 14.4 : An MS Word document embedded in a Netscape Browser (made possible by the NCompass plug-in).

An ActiveX document can also be viewed by Netscape on the local machine. To do this, simply choose File from the menu bar, then Open file... from that menu. From here, you can choose any MS Word, MS PowerPoint, MS Graph, or MS Excel document you wish to view.

A Typical Example

A good example for using ActiveX documents on your company's Intranet can be found at http://www.ncompasslabs.com/ActiveX, Office Integration (see figure 14.5). This example shows how using ActiveX documents can save valuable time, and be efficient for use on the corporate Intranet.

Figure 14.5 : Office integration at Ncompasslabs.com.

Using ActiveX Controls on the Intranet

The power of ActiveX is truly expressed by ActiveX controls. ActiveX controls expand power of plain CGI forms and buttons by providing customizable buttons, list boxes, and other Windows components. ActiveX controls also enable developers to make custom controls that can display movies, connect to databases, and display specialized text (such as vertically positioned).

Embedding Controls into Your Web Page

Embedding controls into your Web page is a little more challenging than pointing to an ActiveX document. ActiveX controls must be embedded using the EMBED tag (for Netscape), or the OBJECT tag (for MS Explorer). Both tags can be used together in a Web page to make the control visible to users with either browser. Also, in order to embed an ActiveX control, you need to have the MSADK (Microsoft ActiveX Development Kit) and use its STM tool to create a stream file for the control. The STM tool is described later in this chapter. The control that you are attempting to embed must also be insertable. You can check to see if the control is insertable by checking the Insert Object menu choice for its availability in MS Word, or a similar Microsoft application. The following HTML script shows an example of embedding a control for Netscape and MS Explorer-the control will only appear once, as either <EMBED> tag will place it into Netscape or <OBJECT> will put it into Explorer:

<html>
<head><title>Sample ActiveX Control</title></head>
Enter some text here
<!Embed an ActiveX control for Netscape (using the Ncompass plug-Âin)>
<EMBED SRC="filename.stm" code="filename.ocx" width=300 height=250 alt="ActiveX control">

<!Embed the same control for MS Explorer>
<OBJECT DATA="filename.stm" code="filename.ocx width=300 Âheight=250>
</OBJECT>
<html>

The EMBED Tag for Netscape

The EMBED tag is used in Netscape to notify the browser that a plug-in is needed for the particular references within the tag. In the case of an ActiveX control, the EMBED tag notifies Netscape that it needs to run the NCompass plug-in to display the control. The EMBED tag takes five attributes to describe an ActiveX control to Netscape. Table 14.1 shows these attributes and their description.

Table 14.1  Attributes of the EMBED Tag
AttributeDescription
SRCSpecifies the location (source) of the specified document.
CODESpecifies the binary code that corresponds to the source.
HEIGHTSpecifies the height that Netscape should use to draw a frame for the control.
WIDTHSpecifies the width that Netscape should use to draw a frame for the control.
ALTSpecifies alternative text for the control should the client not be able to display it.

The Object Tag for MS Explorer

The OBJECT tag is used by MS Explorer to define a specified object for MS Explorer to display. Table 14.2 shows the attributes of the OBJECT tag, and their descriptions.

Table 14.2  The OBJECT Tag Attributes
AttributeDescription
DATASpecifies the location (source) of the specified document.
CODESpecifies the location of the binary definition that corresponds to the source.
WIDTHSpecifies the width that MS Explorer should use to draw a frame for the specified control.
HEIGHTSpecifies the height that MS Explorer should use to draw a frame for the specified control.

The source descriptor should point to the .stm file, which contains the Persistent Properties of the specified control. This file is created by using the STM Tool from the MSADK.

The code descriptor should point to the actual control, which should be an .OCX file.

Where to Get More Information on ActiveX

For more information on ActiveX controls and for examples of the different controls available and how they are used, check out the following URLs:

http://www.ncompasslabs.com/ (The NCompass home page)
http://www.microsoft.com/ie/ (Microsoft's Internet Explorer Web site)
http://www.microsoft.com/activex/controls (Microsoft's ActiveX Control Web site)
http://www.dclgroup.com/ (The Data-Core home page)