Special Edition Using Microsoft® Visual Studio for Enterprise Development

Previous chapterNext chapterContents


- 12 -
Creating Web Browser-Based Applications with Visual Basic

by Joe Lengyel

Gain insight into ActiveX document technology. Learn the impact this paradigm will have on information systems development environments.
Understand the considerations that accompany designing ActiveX documents. Compare how this differs from standard form development.
In a detailed step-by-step discussion, learn how to build an ActiveX document composed of UserDocument objects, controls, forms, and code. Test this application in Internet Explorer.
Learn how to use the ActiveX Document Migration Wizard for converting standard forms to ActiveX documents. Gain an understanding of how to use this tool to leverage existing enterprise applications.
In a detailed discussion, learn about installation and configuration issues. Gain an understanding of how various platforms affect both development and deployment.

The ever-changing landscape of software development is increasingly focusing on the Internet, intranets, and the active platform. The promises inherent in ubiquitous information and communication presents serious challenges for information systems professionals of all types. Similarly, software vendors shoulder the task of providing tools and utilities for software artisans.

Visual Basic is arguably the most widely used application development toolkit available. More lines of Visual Basic code are written today than any other programming language. Furthermore, increasing numbers of software developers--novice and professional--are building applications with Visual Basic.

To meet the challenges of the active platform while building on the sizable base of experienced programmers, Visual Basic offers ActiveX documents. This chapter shows you how to harness the power of this new technology.

Understanding ActiveX Documents

ActiveX documents, the new building block featured in Visual Basic 5.0 (VB5), allow you to build applications that merge with and enhance the elements of I-net (Internet or intranet) sites. Similar to VB forms, ActiveX documents provide a variety of conventional and I-net capabilities, including functionality using the hyperlink object. Although web development has been possible with VB in the past, ActiveX technology introduced in VB5 accomplishes the following:

A real-world example of an intranet scenario will illustrate the benefits of ActiveX documents. Suppose that Company ABC has a traditional client/server application built in VB. This application manages and administrates all aspects of the company's business, including order entry, inventory, product lists, and so forth. The company has a SQL database that supplies data to the user interface through a Remote Data Object. When enhancements are made to the application, the VB project is recompiled and rebuilt, and a new copy of the executable is placed on each user's machine.

Now consider that Company ABC plans to expand its operations and open a second office in another region of the country. The company requires use of the same corporate application previously described. This is where ActiveX documents can be very useful. Information systems professionals can migrate the existing VB application to become an ActiveX document application, which can be deployed on a web server. Users in both company locations can visit the application via their client web browser. Enhancements to the application will appear seamlessly because the web browser determines the runtime requirements of the application and downloads these components to each user's machine.

This is an example of a web-enabled application built with VB. Many of the screens and program logic are reused from the existing corporate application. The ActiveX document can contain the regular assortment of controls in the VB toolbox, as well as any other ActiveX controls that the company is licensed to use. This example shows that ActiveX documents are a web-development alternative to technologies such as HTML and scripting languages such as JScript and VBScript.

Developing on the ActiveX platform presents a host of new challenges and features for application architects. One difficult function is blending the best components of existing software with new and improved components built with the latest tools.

What Is an ActiveX Document?

An ActiveX document can be any particular display of information, such as a word processing document, a data grid, or a chart. You can associate this display of information with a browser because the browser is the tool with which these active viewports of information can be seen. For this chapter, an ActiveX document consists of a UserDocument object, code, and one or more controls from the toolbox placed on the UserDocument.

UserDocument, a new feature of VB5, is the base object of an ActiveX document you develop in Visual Basic. Although the ActiveX document concept isn't new, building an ActiveX document with UserDocument objects in VB5 is new and unique. The UserDocument object is the ActiveX equivalent of a standard VB form, but you need to know the differences that you'll encounter almost immediately.

Development of a standard VB project often begins with a standard form, which becomes the home to various buttons, labels, and code. Development is very similar with an ActiveX document application. You begin with one UserDocument, and similar types of buttons, labels, and code can be added; however, you'll encounter differences in the properties and methods of the UserDocument, as well as in other application-specific features, such as navigating between ActiveX documents. Furthermore, the deployment platform is different because client/server development is fundamentally distinctive from I-net development. The distinctions aren't trivial.

You aren't limited to using only UserDocuments in an ActiveX document application. You can add standard forms and modules to your project, as you might to any standard project. An ActiveX document application (an executable or DLL) can consist of numerous UserDocument objects, as well as the regular assortment of forms, controls, and so on. As the full force of development focuses on I-net applications, the standard features of applications that exist today will gradually fade away. This migration ability is a positive attribute, however, because it means that the logic and functionality of existing components are reusable.


TIP: You first should familiarize yourself with the UserDocument's properties and methods. Press F4 to peruse the properties list; double-click anywhere on the UserDocument to review the methods.

Understanding ActiveX Document Topology

You can think of ActiveX document technology in terms of three layers:

An ActiveX document is made available through a server, which can be a VB executable or DLL. A server is a component that provides the ActiveX document to an ActiveX container such as Internet Explorer. The ActiveX document is served to the browser viewport by the executable or DLL.

The capability to deploy applications for use in browsers allows you to extend your current client/server solutions throughout I-nets. A typical scenario today involves a VB application consisting of a visual front end for presenting data and reporting options to the enterprise users, and a DAO or RDO connection to a database for piping data to controls such as text boxes, grids, and listboxes. These applications typically feature reporting functions to provide documentation to customers and executives.

Administrative efforts needed for providing these reports, along with supporting application end users, isn't insignificant. Annual maintenance and support are large portions of enterprise budgets. As development technology focuses more on I-nets, the separate distribution and maintenance costs for customers and enterprise users will gradually merge. As customers use vendor web sites more to retrieve account information, schedules, product lists, and the like, application development will no longer be split between traditional client/server applications and web applications. Instead, all applications will be browser-based or web applications, and the support and development costs for information systems departments will assume this focus. A single application will serve customers and enterprise users alike and be used within a browser. The components in VB5 contribute to the existing available development tools to make this reality bigger each day.

Selecting a Project Type

VB offers you four types of projects in which to build ActiveX documents:

Major differences exist between projects of the type EXE and those that are DLL. The differences between document EXEs and component EXEs are explained later in this section.


See Chapter 5, "Creating ActiveX Components with Visual Basic."

An ActiveX component can be built as an out-of-process component (an .exe file) or an in-process component (a .dll file) with respect to the use of ActiveX objects. Historically, DLLs have served as building blocks in a reusable component capacity. For example, each new application that needs a network security check can use a DLL that facilitates a network logon. A DLL is an in-process component that runs in the process space of the application that uses it. An in-process component performs more quickly than its counterpart out-of-process component, an EXE, because no cross-process navigation is required; therefore, the performance of a DLL will exceed the performance of the same component compiled as an EXE. In-process components do have drawbacks. A natural security breach occurs whenever calls are made from a calling program to an external file. This type of breach might corrupt a program, so you should take special care to make sure that establishment of connections and passing of parameters are done properly.


NOTE: When the host application is Internet Explorer, trying to show a modeless form from a DLL fires an error condition. Modeless forms and dialog boxes allow the focus to be shifted to other forms and dialog boxes. Modal forms and dialog boxes must be closed before other actions can be taken. A dangling modeless process creates the error condition within Internet Explorer.

EXEs are out-of-process components that run outside the address space of the client application and within their own process. Most applications that you use, such as those in Microsoft Office, are executables. One benefit of out-of-process components is the asynchronous performance achieved as a consequence of the separate client and component processing. In other words, EXEs do multitasking.

One large danger area of ActiveX EXEs is the potential for data disruption. Although this can depend on the distribution method, a single server installation of an EXE functions as a single application being used by many users. In this context, no components are installed on the users' machines. In essence, only one ActiveX application process is taking place, with containers creating separate instances of that process. As a consequence, separate container sessions can simultaneously make transactions, rendering data for one session of the container unexpectedly modified due to changes made through the second container session. Naturally, this problem is an issue within certain contexts. It's not insurmountable--developers deal with these issue types daily--but the volume and scope are larger when an I-net is involved.

The performance for an out-of-process component will be slower than a DLL because of an executable's incapability to make references directly between the client and the component. For example, referrals between a client and a component can't be made by reference. Instead, a copy of the data must be made in the component, which is a slower process than passing by reference.

ActiveX EXEs are COM objects and can be used in applications that support COM. This means executables created with VB will appear, without any special effort on the developer's part, in the list of available object references. When you create a project and designate it as an ActiveX EXE, you're essentially telling VB one of two things:

ActiveX components are web-enabled and can be used on ActiveX documents or elsewhere. Knowing the interaction of the two can be beneficial because the same programming approach and tactics can apply to both. Just remember that if you want to present an interactive interface for an application that will be deployed in an I-net environment, you should create an ActiveX document EXE; otherwise, create your components with an ActiveX EXE.


See Chapter 4, "Using Microsoft's Object Technologies."

Setting Up Project Files

The file set that makes up an ActiveX document application varies from that of a standard application. When you save a form in a standard VB application, two files usually are created for the one form. The form object is stored in a plain text file, which contains the source code and property values. This file gets an .frm extension. Controls on the form that can't be stored as plain text are stored in .frx files. If you've ever accidentally deleted or misplaced an .frx file, you know the form has to be virtually re-created.

Similarly, the source code and property values of UserDocument objects and the code behind the document are stored in plain text files. These files receive a .dob file extension. Controls that can't be stored in .dob files because of their graphical elements are stored in .dox binary files. VB also creates a UserDocument document file when the project is compiled, which receives a .vbd extension and is placed in the same directory as the other project files. The .vbd file is the address file for the application to the container. The sample application that you build later in this chapter shows the significance and use of the .vbd file.


TIP: After you compile your ActiveX document, you can change the extension of the .vbd file--for example, Players.vbd can become Players.nfl. With this capability, users can make the name of the ActiveX document an intuitive mnemonic of the functionality of the application.

Building an ActiveX Document

The general process of creating an ActiveX document is like creating any other project. The following list gives an overview of the steps to take:

1. Start a new project.

2. Select a project type, either an ActiveX document EXE or an ActiveX document DLL. By default, these template projects contain a single UserDocument. Each UserDocument is the core object for an ActiveX document.

3. Add any desired controls to the UserDocument(s).

4. Add other forms, code modules, or more UserDocument objects to the project.

5. Compile and make the project.

6. Deploy the project.

7. View the project in a container.

8. Test and debug the project.


See Chapter 22, "Building Client Front Ends with Visual Basic and RDO."

In the first exercise, you make an ActiveX document from scratch; the exercise for migrating forms to UserDocuments comes later. As you go along, remember the design issues discussed so far.


ON THE WEB:Bear in mind that this exercise requires the use of Internet Explorer. If you haven't installed Internet Explorer, do so now. You can obtain a free copy at http://www.microsoft.com/ie/.

Reviewing Design, Development, and Implementation Issues

Before you build an ActiveX document, review some design, development, and implementation issues:

Creating the Grape Vine Application

In this section, you create an executable ActiveX document and view it in a container. The exercise doesn't guide you through the creation of a rigorous application development, but you place numerous controls onto a UserDocument, write some basic routines, compile and execute the project, and use the application in a container. Nothing you do will be different from what you've probably already done. Your ability to leverage your investment in the VB learning curve will pay dividends here; in fact, as the scope of your web development gets serious, this exercise will prepare you to handle the greater challenges of I-net development.


ON THE WEB:You can find in digital format all the code bits described in this chapter at http://www.gasullivan.com/vs97book/. Save time by performing cut-and-paste operations on the code for the how-to sections in this chapter.

Building the Framework  To build a new ActiveX document, follow these steps:

1. Open a new ActiveX document EXE project. Remember, this project type automatically creates the first UserDocument object for you, which can be found in the project explorer in the User Documents folder. The project explorer is your window to all the objects within the project, such as modules, classes, forms, and so forth. Because VB lets you have multiple projects open simultaneously, the project explorer also organizes your access to all open projects.

2. In the project explorer, select the new UserDocument and activate it by choosing the View Object button located on the toolbar. Press F4 to activate the Properties list for the UserDocument and assign properties to the objects in the project. In step 5, you save the objects as files. These are distinct steps that serve exclusive purposes.

3. Provide the new object with the name FirstUserDoc in the Name property of the Properties list. The name should now appear in the title bar of the object, followed by (UserDocument). The project has no name at this time.

4. Supply a name for the project by choosing Project, Project1 Properties from the menu. Type AxGrapeVine in the space available for the Project Name and click OK. This name now appears in the title bar of the UserDocument; each new UserDocument in the project will bear this name as well. The Ax indicates that this is an ActiveX document project.

5. Save the project by choosing File, Save. When you're asked to save the UserDocument, use the default name FirstUserDoc. (VB provides the default .dob document object file extension for the UserDocument.)

6. Provide the name AxGrapeVine for the project and save it. The project should receive a .vbp file extension.

7. Activate the toolbox and add a command button to FirstUserDoc. Name the command button cmdSommelier. Type Sommelier for the Caption property of the control. Add a second command button, named cmdAbout, and type About for its Caption property.

8. Add a label control. Type the following text in the Caption property of the label:
Welcome! You have located The Grape Vine home page. This site provides assistance with selecting an appropriate wine for your next meal or party. Click the Sommelier button at the bottom to review the Options page.
9. To spice up the home page, add an image control. You can set the Picture property to any bitmap (.bmp) or metafile (.wmf) you choose.

The ActiveX document should now appear like the one in Figure 12.1.

FIG. 12.1
The AxGrapeVine project after addition of OLE controls to the FirstUserDoc UserDocument object.

10. Modify the Click event of cmdSommelier to resemble the following code segment:
Private Sub cmdSommelier_Click()
    OptionsPage.Show vbModal
End Sub
11. Modify the Click event of cmdAbout to resemble the following code segment:
Private Sub cmdAbout_Click()
    frmAbout.Show vbModal
End Sub
12. Add a form to the project. Choose Project, Add Form from the menu. In the Add Form dialog box, choose the blank Form item. Choose Open. A new blank form should now reside in the Forms folder of the Project window.

13. Provide the new form with the name OptionsPage. The name should now appear in the title bar of the object, followed by (Form).

14. Modify the Caption property of OptionsPage by typing the following text:
Choose one or more items from the list boxes; click the Suggest button at any time.
15. Add a command button named cmdSuggest to OptionsPage and type Suggest for its Caption property. Add a second command button named cmdHome and type Home for its Caption property.

16. Add one label control for each of the following Caption properties: Appetizers, Cheeses, Soups, Salads, Pasta, Red Meat, Chicken, Other Meat, Seafood, and Miscellaneous.

17. Add one combo box control for each of the following Name properties: cboAppetizers, cboCheeses, cboSoups, cboSalads, cboPasta, cboRedMeat, cboChicken, cboOtherMeat, cboSeafood, and cboMiscellaneous.

18. Change the Style property of each combo box to 2 - Dropdown List.

19. Add one text box control for each of the following Name properties: txtAppetizers, txtCheeses, txtSoups, txtSalads, txtPasta, txtRedMeat, txtChicken, txtOtherMeat, txtSeafood, and txtMiscellaneous.

20. Save the application. The OptionsPage form should now appear as shown in Figure 12.2.

FIG. 12.2
The OptionsPage form after adding all the controls necessary for the sommelier function.

Adding the Code  Now you add the bulk of the logic for the application. Remember, the code can be cut from the site http://www.gasullivan.com/vs97book/ and pasted where you need it.

1. Add the code in Listing 12.1 to the Load event of OptionsPage.

2. Add the code in Listing 12.2 to the Click event of cmdSuggest.

3. Add the code in Listing 12.3 to the Click event of cmdHome.

4. Create a new procedure and supply it with the name LoadListBoxes. Add the code in Listing 12.4 to the new procedure.

Listing 12.1  The Form's Load Event to Center the Form on the Monitor

Private Sub Form_Load()
     Me.Left = (Screen.Width - Me.Width) / 2
     Me.Top = (Screen.Height - Me.Height) / 2
     LoadListBoxes
End Sub

Listing 12.2  Determining an Appropriate Wine for Each Food Item Selected

Private Sub cmdSuggest_Click()
`routine to suggest wines based on selections in combo boxes
MousePointer = vbHourglass
If cboAppetizers.ListIndex <> -1 Then
     Select Case cboAppetizers.ListIndex
        Case 0
            txtAppetizers.Text = "Light-bodied red wines or whites"
        Case 1
            txtAppetizers.Text = "Semi-dry or sweet wines; light, fruity," _
                                 & "young reds"
        Case 2
            txtAppetizers.Text = "Medium or full-bodied reds"
     End Select
End If
If cboCheeses.ListIndex <> -1 Then
     Select Case cboCheeses.ListIndex
        Case 0
            txtCheeses.Text = "Fruity reds"
        Case 1
            txtCheeses.Text = "Full-bodied reds"
        Case 2
            txtCheeses.Text = "Sweet wines"
        Case 3
            txtCheeses.Text = "Full-bodied reds; fruitier wines"
        Case 4
            txtCheeses.Text = "Creamy whites; champagne; sparkling wines"
     End Select
End If
If cboSoups.ListIndex <> -1 Then
     Select Case cboSoups.ListIndex
        Case 0
            txtSoups.Text = "Medium-bodied reds"
        Case 1
            txtSoups.Text = "Light white wine"
        Case 2
            txtSoups.Text = "Full-bodied reds"
        Case 3
            txtSoups.Text = "Light-bodied whites"
        Case 4
            txtSoups.Text = "Fruity reds"
     End Select
End If
If cboSalads.ListIndex <> -1 Then
     Select Case cboSalads.ListIndex
        Case 0
            txtSalads.Text = "No wine recommended"
        Case 1
            txtSalads.Text = "High-acidic wines"
        Case 2
            txtSalads.Text = "Dry whites"
        Case 3
            txtSalads.Text = "Fruity reds or whites"
     End Select
End If
If cboPasta.ListIndex <> -1 Then
     Select Case cboPasta.ListIndex
        Case 0
            txtPasta.Text = "Light, fruity reds and blush wines"
        Case 1
            txtPasta.Text = "Full-bodied reds"
        Case 2
            txtPasta.Text = "Light-bodied reds; dry whites"
        Case 3
            txtPasta.Text = "Dry white wine"
     End Select
End If
If cboRedMeat.ListIndex <> -1 Then
     Select Case cboRedMeat.ListIndex
        Case 0
            txtRedMeat.Text = "Medium- or robust-bodied reds"
        Case 1
            txtRedMeat.Text = "Robust full-bodied reds"
        Case 2
            txtRedMeat.Text = "Fruity young reds"
        Case 3
            txtRedMeat.Text = "Full-bodied reds"
     End Select
End If
If cboChicken.ListIndex <> -1 Then
     Select Case cboChicken.ListIndex
        Case 0
            txtChicken.Text = "Medium-bodied reds; white wines"
        Case 1
            txtChicken.Text = "Roses; blush wines"
        Case 2
            txtChicken.Text = "Crisp, oaky-flavored wines"
        Case 3
            txtChicken.Text = "Full-bodied reds"
     End Select
End If
If cboOtherMeat.ListIndex <> -1 Then
     Select Case cboOtherMeat.ListIndex
        Case 0
            txtOtherMeat.Text = "Medium-bodied reds"
        Case 1
            txtOtherMeat.Text = "Light reds; roses, blush wines"
        Case 2
            txtOtherMeat.Text = "Full-bodied reds"
        Case 3
            txtOtherMeat.Text = "Full-bodied reds; dry whites"
        Case 4
            txtOtherMeat.Text = "Full-bodied, robust reds"
     End Select
End If
If cboSeafood.ListIndex <> -1 Then
     Select Case cboSeafood.ListIndex
        Case 0
            txtSeafood.Text = "Crisp, light whites"
        Case 1
            txtSeafood.Text = "Light reds; crisp, young whites"
        Case 2
            txtSeafood.Text = "Full-bodied whites"
        Case 3
            txtSeafood.Text = "Full-bodied reds"
        Case 4
            txtSeafood.Text = "Full-bodied whites"
        Case 5
            txtSeafood.Text = "Champagne; sparkling wines"
        Case 6
            txtSeafood.Text = "Medium-bodied reds"
        Case 7
            txtSeafood.Text = "Champagne; sparkling wines"
        Case 8
            txtSeafood.Text = "Delicate whites"
     End Select
End If
If cboMiscellaneous.ListIndex <> -1 Then
     Select Case cboMiscellaneous.ListIndex
        Case 0
            txtMiscellaneous.Text = "Dry white wines; champagne"
        Case 1
            txtMiscellaneous.Text = "Beaujolais; fruity reds; blush whites"
        Case 2
            txtMiscellaneous.Text = "Sweet wines; champagne"
     End Select
End If
MousePointer = vbDefault
End Sub

Listing 12.3  Unloading the Current Form and Returning Users to the Home Page

Private Sub cmdHome_Click()
Unload Me
End Sub

Listing 12.4  Loading All Listbox Controls with Items from Which Users Can Select

     Public Sub LoadListBoxes()
`fill the Appetizers cbo
     cboAppetizers.AddItem "Antipasto"
     cboAppetizers.AddItem "Pate"
     cboAppetizers.AddItem "Toasted ravioli"
`fill the Cheeses cbo
     cboCheeses.AddItem "Mild"
     cboCheeses.AddItem "Strong/aged"
     cboCheeses.AddItem "Blue cheese, Saga"
     cboCheeses.AddItem "Goat cheese"
     cboCheeses.AddItem "Brie/creamy cheese"
`fill the Soup cbo
     cboSoups.AddItem "Hearty soup"
     cboSoups.AddItem "Lighter soup"
     cboSoups.AddItem "Stew"
     cboSoups.AddItem "Clam chowder"
     cboSoups.AddItem "Cheese soup"
`fill the Salad cbo
     cboSalads.AddItem "Vinegar dressing"
     cboSalads.AddItem "Herb dressing"
     cboSalads.AddItem "Creamy dressing"
     cboSalads.AddItem "Sweet dressing"
`fill the Pasta cbo
     cboPasta.AddItem "Primavera/vegetable sauces"
     cboPasta.AddItem "Hearty tomato sauces"
     cboPasta.AddItem "Shellfish sauces"
     cboPasta.AddItem "Cream/white sauces"
`fill the Red Meat cbo
     cboRedMeat.AddItem "Barbeque"
     cboRedMeat.AddItem "Game"
     cboRedMeat.AddItem "Grilled or roasted"
     cboRedMeat.AddItem "Steak"
`fill the Chicken cbo
     cboChicken.AddItem "Roasted or grilled"
     cboChicken.AddItem "Chicken salad"
     cboChicken.AddItem "Chicken with cream sauce"
     cboChicken.AddItem "Duck"
`fill the Other Meat cbo
     cboOtherMeat.AddItem "Veal"
     cboOtherMeat.AddItem "Ham"
     cboOtherMeat.AddItem "Pork roast"
     cboOtherMeat.AddItem "Pork chops"
     cboOtherMeat.AddItem "Lamb"
`fill the Seafood cbo
     cboSeafood.AddItem "Grilled"
     cboSeafood.AddItem "Full-flavored fish"
     cboSeafood.AddItem "Swordfish/tuna"
     cboSeafood.AddItem "Fish in cream/butter sauce"
     cboSeafood.AddItem "Lobster"
     cboSeafood.AddItem "Salmon"
     cboSeafood.AddItem "Smoked fish"
     cboSeafood.AddItem "Sole"
`fill the Miscellaneous cbo
     cboMiscellaneous.AddItem "Fruit"
     cboMiscellaneous.AddItem "Cold cuts"
     cboMiscellaneous.AddItem "Dessert"
End Sub

Creating an About the Grape Vine Box  As discussed earlier, a good feature of a web page is to have an About box. Users can refer to this useful tool for understanding the whereabouts and purpose of the web site, as well as other useful application-pertinent facts. To add an About box to the Grape Vine application, follow these steps:

1. Choose Project, Add Form from the menu.

2. In the Add Form dialog box, select the About Box item and choose Open. A new About Box template form now resides in the Forms folder of the Project window.

3. Change the text property for each label control on the form, using the following example text as a guide:
4. Create a new procedure that will center frmAbout when it's loaded. Add the code in Listing 12.5 to the Load event of the form frmAbout.

The form frmAbout should appear as shown in Figure 12.3.

5. Compile the project and correct any syntax errors that occur. Save the project again.

6. Create an EXE by choosing File, Make AxGrapeVine.exe from the menu.

Listing 12.5  Centering the Form Onscreen

Private Sub Form_Load()
     Me.Left = (Screen.Width - Me.Width) / 2
     Me.Top = (Screen.Height - Me.Height) / 2
End Sub

FIG. 12.3
An About box is a useful mechanism for conveying location and context to visitors of a web site.

Testing the Grape Vine

You can now execute the application, but remember that this application can't be viewed in the IDE as a standalone application. You must view and debug the application with the aid of a container. To do this, follow these steps:


NOTE: The CreateToolWindow method, in this context, allows you to create a dockable window in the IDE for the purpose of debugging an ActiveX document. The process of opening a browser window for each test of the application can become tedious. CreateToolWindow partially sidesteps this hassle by facilitating everything in the IDE.
1. Run the project by choosing Run, Start from the menu or by pressing F5.

2. Start Internet Explorer. If you aren't online, Internet Explorer will present you with an error message similar to the one in Figure 12.4. It's not a problem--click OK.


TIP: The message means Internet Explorer attempted to connect to the Microsoft home page, Internet Explorer's default URL, and an online connection didn't exist. To prevent this type of message from occurring, make a local URL the default startup page for the browser. After you choose OK, Internet Explorer resorts to loading a local HTML page into the container until you supply a new URL. The URL for the generic local HTML page shown is C:\windows\system\blank.htm.

FIG. 12.4
Internet Explorer provides feedback when an URL address can't be located.

3. In the address box of Internet Explorer, enter the path and name of the ActiveX document now executing (the path on your machine might not be the same as this one):
D:\VSD\ActiveXExe\FirstUserDoc.vbd
FirstUserDoc.vbd loads and appears in the container window (see Figure 12.5).

FIG. 12.5
Viewing the startup page of the AxGrapeVine project in the Internet Explorer container.

4. Before doing anything more, add the URL address to your Favorites list by choosing Favorites, Add to Favorites from the container menu. For debugging purposes, having the URL predefined to a mouse click saves you time and patience.

5. Click the buttons to observe the functionality. Click the About button to make the About box appear. Click the Sommelier button to open the OptionsPage form (see Figure 12.6).

FIG. 12.6
The container viewport while using the Sommelier feature of the Grape Vine ActiveX document.

The application should remain running in the IDE; however, each time you make a change in the application, you must stop and restart Internet Explorer to clear its list. This is where the Favorites entry comes in handy. Depending on the sophistication of the application, the debugging process can be simple or difficult. You might try developing the application as a standard VB project first and migrate it afterward to an ActiveX application, so you can use the debugging talents you've honed during development of standard VB applications. You'll become more accomplished at debugging ActiveX documents with time and experience.

Working with Menus

Now you need to add a menu to the UserDocument. In this exercise, the menu calls up the About box in the container viewport. You create this menu for the About box in the VB development environment. If the Grape Vine application is still running, stop it now. To create the menu, follow these steps:

1. Bring up the menu editor by right-clicking the UserDocument.

2. In the menu editor, add entries for mnuHelp and mnuAbout.

3. Add the caption Help to the menu item mnuHelp. Add the caption About The Grape Vine to the menu item mnuAbout. Make mnuAbout a submenu of mnuHelp by selecting the right arrow in the middle of the dialog box.

4. Your completed entries should appear as in Figure 12.7. Click OK to close the menu editor and save the menu entries.

FIG. 12.7
The Menu Editor depicts the items added to the menu of the ActiveX document.

5. Add the following code to the On_Click event of mnuAbout:
frmAbout.Show vbModal
6. Save the project and create a new executable.

7. Press F5 to execute the project.

The menu items added in these steps should now appear on the container's menu bar. To test the menu items, open the About box. From here, you can augment and enhance the application.


TROUBLESHOOTING: My container menus are not displaying. Containers won't exhibit their menus correctly unless the ActiveX document successfully merges the application's Help menu with the container's Help menu. The jump from the .htm file to the .vbd file interrupts any chance of having this merge occur successfully. The workaround for this is to have the .vbd file load directly. Menu merging is still an infant capability and a trial-and-error process.

Looking at Installation and Configuration Concerns

You've created an ActiveX document and are ready to deploy. This means, in all likelihood, you need to use the Application Setup Wizard that comes with VB5. Although you can create a custom setup wizard, the version VB offers is robust and about what most installations need. The VB setup kit is configurable through the user interface (UI), and even more so for the experienced developer.


CAUTION: Be careful when modifying any features of the VB setup kit--the fault tolerance for overwriting an important file at a user's desktop might be zero.

You'll find that installing an ActiveX document is a lot different than installing a standard VB application. You no longer need heaps of floppies or even a CD-ROM with runtime and dependency files. Certain steps associated with Internet setup are made easier, but others--including heterogeneous platform issues--make deployment much more challenging. You might be deploying an application for the known world to view, not just the end users down the hall.

Using Internet Download Setup

The setup utility, with your interaction, builds an installation program for deploying the application on clients and servers across LANs, WANs, and I-nets. Although VB5 still possesses the standard setup program option, the Professional and Enterprise Editions include a new feature for creating an Internet download setup. This way, you can create a setup for ActiveX projects, including projects that contain UserDocuments. The wizard facilitates the installation and use of an application in one of two ways:

Which method you choose has everything to do with the target location you have in mind during requirements planning and development. In other words, it's about scope. Know your audience. You should use the Internet Download Setup for any I-net-based application.

Understanding Browser-Initiated Installation

By far the biggest paradigm shift you'll encounter when deploying active applications is the installation. In the past, software was installed at each client or network share point. Internet setups work much differently. As you build the setup, the wizard collects necessary files and places them in a specified location, which can be a web server or a network server. (Eventually the files need to be placed in a location that the I-net can access.) There they will sit, waiting to be reached by the next browser.

The next time the URL address of the application is specified by some browser out in the ether, the application will be installed at the client computer--that is, the browser drives the installation. As the browser attempts to load the default ActiveX document screen, it compares the application requirements and the resources of the local computer. The browser then downloads and registers any differences identified by the comparison. Although the browser handles this workload, it does so objectively, and any missing components prevent the proper installation and subsequent use of the ActiveX application.


See Chapter 10, "Clients, Servers, and Components: Web-Based Applications."

Stepping Through the Setup

In this section, you step through the process of creating an Internet download setup, installing the application, and viewing the application in a container. First, start the Application Setup Wizard. After reading the Introduction dialog box information, click Next to proceed to the Select Project and Options dialog box (see Figure 12.8).

FIG. 12.8
The Select Project and Options dialog box lets you choose the project file and specify setup program options.

Click the Browse button and locate the AxGrapeVine.vbp project file. Select the Create Internet Download Setup option. Choosing the Rebuild the Project option recompiles the project and builds a new executable. You've performed these tasks already, so leave the checkbox for this option clear and click Next to continue.


NOTE: In general, you won't have much need for the Rebuild the Project option. Having a cleanly compiled and built executable before using the setup program is best.


ON THE WEB:The Select Project and Options dialog box features a hyperlink to information on Internet download from Microsoft. The link takes you to http://www.microsoft.com/vbasic.icompdown, where you can find web-development content for Visual Basic.

The Internet Distribution Location dialog box requires you to specify a path where the download files will be placed (see Figure 12.9). At this time, select any location your computer has been mapped to; in the future, bear in mind that you must choose a location accessible via an HTTP transaction by users who might have guest permissions or less.

FIG. 12.9
The Internet Distribution Location window allows users to specify a source location where the wizard can install the application files.

The Internet Package dialog box, shown in Figure 12.10, allows you to specify whether parts of your distributed application will be located at a Microsoft web site and linked to the remaining components. The setup wizard creates a primary cabinet (.cab) file and encloses in it items such as ActiveX controls, EXEs, documents, and DLLs. For ActiveX-based projects, one or more additional .cab files are created to store all additional controls and referenced objects (such as RDO 2.0).

FIG. 12.10
The Internet Package dialog box allows users to specify a source for component download.

If you're distributing this application across the Internet, it's advisable to choose Download from the Microsoft Web Site. If you're distributing this application across your intranet, choosing the Use Alternate Location option is more appropriate. For example, an intranet application in an environment with no Internet access can still support ActiveX documents if the necessary .cab files are placed in the setup directory. All the .cab files are available at the Microsoft web site or on the Visual Basic CD-ROM and can be copied to the network server and used by the application. Each method has its benefits, but generally you want to consider speed, security, and version management. Most important, know the objectives you want to achieve for the application and the enterprise, and choose your installation method accordingly.

Choose the Use Alternate Location option for this exercise. Leave the text box blank to default to the previously selected setup location.

Click the Safety button to personally indicate project components you decide are safe for the user environment. The options Safe for Initialization and Safe for Scripting are available only for Internet installations. Exercise caution when assigning either option unless you're absolutely sure of these assertions. Furthermore, your .cab files must be fully signed before you can make complete use of these features. Click Cancel to close the Safety dialog box and then click Next to continue.


NOTE: Signed refers to a digital signature applied to distributed software components to indicate who created the component. It's an assurance by the creator that the component won't damage the user's computer. Signing doesn't completely ensure that an installed component won't damage a user's system, but it does create a path from the user to the creator in case the software harms the system. Developers can be held liable in some instances when installed components cause damage.

In the ActiveX Server Components dialog box, you can specify local or remote ActiveX server components, such as ActiveX EXEs, DLLs, or OCXs (see Figure 12.11). The selection of these components might seem daunting, but it isn't--the hard part is planning and developing local or remote server components. Suppose that you develop a remote ActiveX EXE for the Grape Vine to function as a data-collection agent. A single server can collect data from disparate, geographically dispersed data sources, perform aggregations on the data, and serve the data back to a client application. You can position this server remotely and benefit from single-point maintenance, improving network performance by eliminating the need to pass large volumes of raw data across a LAN or WAN. Conversely, if a screen refresh is most important, locally positioned components are more advantageous. You should rely on the local default option at this time because no server components are involved in the Grape Vine application. Click Next to continue.

FIG. 12.11
The Active Server Components dialog box allows users to select local or remote application servers.

The File Summary dialog box gives you a chance to review or add runtime files to be distributed with the application. This step usually requires you to make some file additions to the list. Knowing which files to include requires an exhaustive understanding of the support files that must accompany all components, third-party or otherwise, in your application. Third-party vendors often include runtime distribution lists with their products. You should always build your install set and test it on a clean machine--that is, a machine without the runtime components that you're distributing--to ensure that you won't have problems after the fact. Don't expect the setup wizard to include all the necessary files by default (it won't), and you'll experience iterations of building, testing, and troubleshooting before you meet with success.

Figure 12.12 shows the File Details dialog box, in which you can exert significant control over the execution of the setup program. In this dialog box, you can view or change where files will be installed on the end user's machine. For example, an option exists to install the selected component as a shared file. As this implies, other applications will have use of the component. If a series of installs will be made, each requiring the use of the file in question, this option is useful, but you should exercise caution and modify this file option only if you're sure of your actions. If a shared ActiveX component is installed to different folders, removing one file instance might result in removal of the Registry information that makes the remaining copies accessible, rendering the remaining components inaccessible. You definitely want to test any changes you make to the default settings. For this installation of the Grape Vine, all default settings are appropriate. Click Next to accept the current list of runtime files.

FIG. 12.12
The File Details dialog box allows users to view and change the installation information for files to be delivered with your I-net application.

You can click Save to store the setup template for future use. Remember to choose an appropriate location and assign a useful mnemonic name.


NOTE: You can modify the setup template in any common text editor. Current VB documentation cautions strongly against this unless you're a very experienced developer. In reality, it isn't that serious. Your first installation should be on a test server, anyway. Be sure to make a copy of the setup file before modifying it. If the setup doesn't go as you want it to, you can compare the two files to see where you might have erred.

Select the Finish button to complete the setup process. The setup program will be built in short order.

The setup program creates several files to manage the installation and execution of the application:

Testing the Setup

Internet Explorer visits the .htm file to install the application. The other files act in a support capacity during the installation process. To test the setup program, follow these steps:

1. Start Internet Explorer.

2. Choose File, Open from the menu.

3. In the Open dialog box, choose the Browse button.

4. Locate and select the AxGrapeVine.htm file. Choose the Open button. The text box in the Open dialog box fills with the AxGrapeVine.htm file and path.

5. Choose OK.

The installation of the application begins. Almost immediately a warning message appears, explaining that one or more of the components to be installed isn't verifiably safe. This happens because the safety checks weren't selected during the setup process. Be sure to heed the admonitions of this message. If you're not sure of the security implications, you should cancel the setup.


TROUBLESHOOTING: Certain components consistently fail to download. At this writing, browsers won't download components successfully with the browser security level set above medium. You probably need to take security completely off for some components to work at all. Because this can compromise the security directives of your enterprise, understand how component download affects the development effort. Also bear in mind that most users choose to cancel download operations from web sites they have arrived at as visitors or guests. Communicate the download process effectively to all those intended users so that they'll know exactly what to expect and how they are to respond.

The application installation completes in short order, and the FirstUserDoc ActiveX document appears in the browser window.


TIP: Test the setup program on a machine that now doesn't contain either a VB IDE or any of the ActiveX components in the project. Test the installation on multiple operating systems and environments to ensure success.

Understanding Integration Issues

Serious development always leads to a stage when software integration and implementation become necessary. A basic part of development involves understanding the environment in which the application will be deployed. ActiveX technology developed in VB5 isn't different from other development tools. Some platforms are well suited for VB5 applications; others clearly aren't ready to be the target platform. Various client/server and I-net development technologies exist because of the diverse platforms on which enterprises and end users function. With that in mind, a discussion about platform capabilities is beneficial here.

Although some development tools are supported on multiple platforms, Visual Basic isn't one of them. Simply put, when you develop in VB, it's done on a PC. You can use a distributed VB application on various platforms, although all-encompassing, cross-platform deployment isn't the primary charge of VB; however, users on various platforms with different browsers can visit an executing ActiveX VB application. VB does allow you to create an Active Server Page (ASP), making the functionality accessible by all browsers, whether running with Windows, Apple Macintosh, or UNIX operating systems. Also, Visual Basic completely supports ODBC, making ODBC databases on any platform accessible through common, object-oriented data-access mechanisms. For these reasons, it's important to understand and appreciate the concerns that arise in cross-platform environments (see Figure 12.13).

FIG. 12.13
An Internet connectivity scenario. Although the type of technology can vary, such as a network operating system, the topology is pretty standard.

Platforms

Imagine that the web server in Figure 12.13 can be a Windows NT or UNIX server; the NOS can be Windows NT, Novell, Banyan Vines, or UNIX; and clients on the network can include Windows NT, Windows 95, Windows 3.1, Macintosh, UNIX, or OS/2. The collection of technology assembled to achieve enterprise I-net connectivity can be quite diverse, making development a conceptually daunting challenge. Business or organization demands often pair combinations of platforms that seem mutually exclusive. For developers, supporting the concept can be withering. At the same time, developers demand the programming tools that allow them to assemble open applications to meet these needs. Your biggest concerns as a developer should be the browsers, the installation platform, data access (if any), and security.

The trend in I-net access is to integrate browsing facilities into nearly every facet of enterprise information systems. Content creators and developers are beginning to retire the notion of anything standalone, beginning to think instead of a whole new online application environment where browsers offer omnipotent control to users. This not only provides a more seamless end-user experience, but also enables a new class of exciting I-net development.

Many developers have a significant investment in knowledge, tools, and components based on a particular language. Thus, the browser must provide broad support for the creation of ActiveX controls or other software components in popular languages such as VB, Java, and C++. Customers--specifically, developers and webmasters--are demanding more from browser architecture. Consider that developers want an open browser architecture that supports all available programming languages and is consistent among various user environments, such as Windows and Macintosh. Customers also want tools that support rapid application development, with the capability to integrate operating systems and browsers to their proprietary software solutions.


ON THE WEB:Although it isn't necessary, some corporate intranets feature a customized browser. Many intranets are strictly internal and are used with a corporate-established browser. Many organizations want to create and distribute a web browser that reflects the specific needs of their organization and end users. In this context, the target for an application is predefined, and development is easier for that reason. You can develop a customized corporate browser with a tool such as Internet Explorer Administration Kit. You can find more information about Internet Explorer's Administration Kit at http://www.microsoft.com/ie.

Browsers

The dominant browsers of the day include


NOTE: Check with your software vendor for available Internet Explorer versions per platform. Each new version becomes more sophisticated and offers greater support of ActiveX and HTML technology. Understand the demands that will be placed on your enterprise browser before making any decisions.

Internet Explorer is a family of products that supports a broad range of platforms and is produced in many languages. Microsoft offers Internet Explorer for the Macintosh, Windows 95, Windows 3.1, and Windows NT platforms. It's built to take advantage of the strengths of each major platform, thereby providing increased capabilities without burdening users with a new learning curve. Because of UI consistency, end users can take advantage of key operating-system features while easily changing platforms. Invariably, developers find the broadest range of capabilities by targeting Internet Explorer as a browser.

The merits and demerits of the other browsers won't be discussed, but you can expect the other products to require a special plug-in or added capability before they can host an ActiveX document.

The only server platform that readily accepts a VB ActiveX document installation is Windows NT Server. Although this seems limiting, consider the market share and inroads Windows NT Server has achieved in recent years. Numerous administrative and security characteristics make Windows NT Server an excellent server platform. Because VB and Windows NT are products of the same vendor, the marriage is very comfortable.

The PC is the most widely used desktop platform. Although you can't install a VB application directly to a Macintosh or UNIX workstation, these platforms can use a VB ASP in a browser.

Security

If you're worried about security, that's good. If you aren't sure that your environment is secure, that's bad. Most important is to have a security plan and to monitor, revise, and update your security plan and implementation periodically. In this realm are database security, network security, and application security. Database security is discussed more in the next section.

Network security can be discussed from the standpoint of Internet users and intranet users. The presence of an Internet server and network firewall by themselves offers good security. Internet users navigate to a web site by using a public URL, and an Internet server translates that address into an internal address, hidden to anyone outside the enterprise. Effective Internet server administration and management built on a foundation of solid security measures can provide rigorous protection to the network.


ON THE WEB:You can obtain more information about Internet security on the Internet. A simple query, using a search engine such as Yahoo! or AltaVista with the words security AND internet, will return plenty of information and links on the subject. If you want a more organized source, find a book that discusses the Internet and its numerous topics, including security. You'll find many Internet books at http://www.mcp.com/que.

If contemplated and developed correctly, applications can be quite secure. The important point is to establish a series of protective firewalls that accomplish the following:

Data Access

Your application very likely will interact with a data source. Applications that interact with a database expose developers to a whole new set of issues:

A serious and legitimate concern for database administrators is protecting enterprise databases from unauthorized access and tampering. Protecting data viewed and used by enterprise users is much less of a concern than exposing corporate data to the world via web sites. Many Internet users preoccupy themselves by hacking into secure databases and corrupting or illegally using data. People find a way to breach security, even on the most protected networks and databases, so the concern administrators have about protecting the privacy and integrity of enterprise data is very real.

Consider a financial institution that makes account information available to customers through a web site. Administrators must provide a secure system to prevent unauthorized access to private account data. Implementing the right topology and architecture greatly reduces the threat of a security breach. It's important to position the components to hide specific names and paths of servers, executables, databases, and files. This means privileged information shouldn't be readily available by viewing the HTML source code through the browser's View menu. Because ActiveX documents are based on UserDocument objects and not HTML specifically, source code is encapsulated and hidden from end users.

As with any application, data needs to be protected from accidental user corruption. The ability to corrupt data is a function of the privileges users are given. Obviously, users with read-only permissions have virtually no chance of directly polluting data through the UI, as long as the interface is developed correctly. Many users, however, are given desktop tools and database access with CRUD (create, read, update, and delete) permissions, in the interest of productivity. This type of user, wielding a database access tool, can cause damage if left unsupervised. Give enterprise users the minimum of permissions. Don't be too quick to give additional authorization to users who appear more savvy and want to be more productive. This is exactly the type of user who might take chances and make mistakes at the expense of valuable data.

The biggest fear is unauthorized remote users. No one can do much about unauthorized users with legitimate passwords. You can hope such a user's access will tip itself off eventually, at which time the password can be changed. Keep close tabs on remote users. Never give remote users more than read privileges unless absolutely necessary. Business processes that require more permissions should be heavily scrutinized. Remember, inadequate database security not only jeopardizes confidentiality of data, but also your ability to maintain database integrity. It's a cost any enterprise can ill afford.

Understand the demands a web site places on the database, the network, and the company infrastructure. Today's users don't have patience with slow throughput, so determine your expected user volumes, peak demand periods, and appropriate hardware resources accordingly. Optimize the cost benefit of hardware resources. Often, departments can lease time and web space from company web and database servers. The benefits of this arrangement include maintenance off load and cost savings.

Will the application share data between documents and forms? If so, particular care must be taken when developing variables and variable scope. Understand these types of implications when targeting for a multicontainer distribution. Take particular care in reviewing forms that have been migrated by using the Migration Wizard; these forms can be prime candidates for data-integrity violations.

From Here...

A time and place will come when all applications will have been ported to enterprise intranets and new development will be only Active in format. New development will be targeted specifically to I-net solutions and built with ActiveX technology. This chapter discussed how to implement ActiveX documents. You built an ActiveX document application and migrated objects from existing standard applications into your ActiveX application. For more information on some of the topics addressed in this chapter, see the following chapters:


ON THE WEB:For a look at multimedia creation tools for I-net applications, see "Web Content Creation Tools and Utilities" on the web page at http://www.gasullivan.com/vs97book/.


Previous chapterNext chapterContents


© Copyright, Macmillan Computer Publishing. All rights reserved.