Please support VBWM through our sponsors


Articles

Beginners' Pages

Online magazines

Vendors pages

Job Market

News Group Express

World of Sites

International Vendors

Tips and Tricks

Advertising

Mission

Reader Surveys

Register for reduced prices and FREE stuff

Developing Web Database Applications using VB 5.0 & MDAC Part II – Using ActiveX Documents to implement the user interface for VB Internet applications

by Karthik Ravindran

 

In the first article of this series I had outlined a methodology for designing and developing web database applications using Visual Basic 5.0 and Microsoft Data access components. A prototype application along with it’s intended architecture, and some sample code segments were used to illustrate the application of these technologies as effective tools for developing web database systems.

This and the subsequent articles in this series will dwell deeper into each of the components that were identified as the deployment technologies for RINFO [ the prototype application defined in my earlier article ‘An Introduction to developing Web database applications using VB 5.0 & MDAC ]. The focus of this writing will be to introduce the readers to the design and development of ActiveX Documents using Visual Basic 5.0. ActiveX Documents will be used in the development of RINFO to implement the Internet downloadable user interface screens. This technology can be used to download and launch screens possessing all the standard features of a Windows GUI from within the Internet Explorer browser window.

I will begin by addressing some of the essential background information [ related to the ActiveX technology and ActiveX documents ] that one needs to be familiar with, before proceeding to the actual coding and development issues.

 

Component Software development & the ActiveX technology :

Component Software development is one of the most prominent trends in the S/W industry today. The objective of component development is to cut development time by making it possible for developers to reuse standardized and tested S/W components to build new applications. The realization of this objective relies to a large extent on the availability of a diverse set of reusable components that address a wide range of implementation issues.

The COM [ Component Object Model ] architecture has revolutionized this concept by defining a set of specifications for the design and development of reusable S/W components. These specifications constitute a standard which has been widely accepted throughout the S/W industry. COM is not concerned with the actual implementation language that will be used to develop S/W component. It only defines the standards that need to be adhered to by component developers. In order to be ‘reusable’ in the true sense of the word a component should be language independent, and should be accessible from programming environments other than the one using which it was developed.

The ActiveX technology from Microsoft can be looked upon as an implementation base for the COM specification. Visual Basic 5.0 can be used effectively to design and develop a variety of reusable components which comply with the COM specifications. ActiveX controls, ActiveX Documents, and code components [ ActiveX DLL’s ] are examples of language independent reusable objects that can be created using VB5.

Component S/W development and the ActiveX technology should not be confused with OOP. OOP is an approach to build object based components which are specific to a particular programming environment, while ActiveX is a technology which allows one to develop, integrate, and reuse object based components created using many different tools.

 

What is a VB ActiveX Document application ?

A Visual Basic ActiveX document application is a VB application for the Internet. ActiveX Documents can be used to implement Internet downloadable user interface screens which can possess all the characteristics of a standard Windows GUI. In the simplest terms, an ActiveX document is an Internet downloadable VB form. Developing an ActiveX document is very similar to developing a standard non-MDI VB form. These documents can be installed on a web server, and downloaded to a client machine where they can be viewed from within the Internet Explorer browser. They can display all the standard windows and advanced ActiveX controls thereby providing the users with a Windows like interface to the application. It is also possible to invoke standard Visual Basic forms [ with the exception of MDI forms ] from within an ActiveX document. This feature is of significant advantage in projects that are targeted at migrating existing VB applications to the web.

Types of ActiveX Documents :

An ActiveX document can be implemented as a DLL [ in-process component ] or an EXE [ out-of-process component ]. An in-process ActiveX document application can only run within the context of a parent application [ the IE browser ], while an out-of-process component can also execute as a stand alone application. The performance of an in-process ActiveX document DLL surpasses that of compiled out-of-process EXE. However the one drawback with the DLL is that it cannot invoke modeless forms. Any form invoked from an in-process ActiveX Document DLL will have to be activated by using the vbModal argument with it’s Show method. A notable disadvantage in the case of an out-of-process ActiveX document, is that multiple users accessing the same .exe can overwrite the global data defined in it’s context.

 

Using ActiveX documents in the development of web database applications :

ActiveX documents can be used in two ways while developing a database application for the Internet :

Method 1 :Using an ActiveX document to implement the menu screen

A single ActiveX document can be used to implement the main opening interface screen of an application. This screen can display the various menu options available to the users to access further functionality. Standard Visual Basic forms which can be invoked from within this document can be used to implement the other interface screens. This method will allow the developer to reuse the existing non-MDI forms while migrating an existing application to the web.

Method 2 : Implementing all the interface screens using ActiveX documents

The second approach is to implement all the user interface screens as Internet downloadable ActiveX documents. These documents can either be developed fom ground up, or the ActiveX document migration wizard that ships with VB5 can be used to convert existing non-MDI Visual Basic forms into ActiveX documents

We will follow the first approach in developing the web version of RINFO. ActiveX documents will be used to implement the logon & the main interface screen. The other interfaces to record and view customer, project, and revenue information will be developed using standard VB forms.

The subsequent sections will address the following :

  • Implementation of the ActiveX document that will serve as the logon screen for RINFO
  • Generating the Internet downloadable setup files for this ActiveX document
  • Downloading and viewing the ActiveX document from within the IE4 browser window

 

Implementing an ActiveX Document :

Implementing an ActiveX document in VB is exactly similar to building a standard form object.

This section will outline the steps that need to be followed to implement the logon screen of RINFO as an ActiveX document.

Steps for designing the layout of the ActiveX Document required to implement the Logon screen of RINFO :

  • Open a new ActiveX Document DLL project
  • The project hierarchy will list a folder called ‘User Documents’. This folder contains an ActiveX document [ UserDocument1 ] whose layout in the design window will be similar to that of a VB form. Notice that unlike a standard form, the ActiveX document does not contain a control menu, a caption bar, and the maximize & minimize buttons.
  • Invoke the properties window of UserDocument1, and change it’s name to LogOnDoc
  • Invoke the properties window for the project [ Project1 ], and make the following settings :

- Project Type : ActiveX DLL

- StartUp object : None

- Project Name : RinfoLogon

  • Resize the Document in the design window if necessary, and add to it the user interface controls as specified in the table below :
Type Name Caption/Text
Static text St_UserId User Id :
Static Text St_Password Password :
Single line edit Sle_UserId Blank
Single line edit Sle_Password Blank, PasswordChar - *
Command Button Cmd_OK OK
  • Save the document [ File -> Save LogOnDoc ] as LogOnDoc.dob in a selected directory. [ Note : .dob is the extension that VB uses for ActiveX documents. ]
  • Save the project [ File -> Save Project ] as RlogOn.vbp in the same directory.

  

Writing code for the Cmd_OK command button to verify the entered user name & password :

The code attached to the ‘Click’ Event of the command button Cmd_OK will verify the validity of the User id and password entered in the logon screen. This code will have to establish a connection with the remote web database to cross verify the existence of the entered id and password in the ‘USER’ table. Prior to writing the code make sure that the Remote Data Services and the ActiveX Data Objects type libraries are included in the project’s references. These type libraries get registered in the PC while installing MDAC.

Code for the ‘Click’ Event of the cmd_OK command button :

Private Sub Cmd_OK_Click()
‘Define a new DataSpace object
Dim objDataSpace As RDS.DataSpace
‘Define an ADOR.recordset object to receive the data retrieved from the Remote ‘server
Dim recset As ADOR.Recordset
‘ Define a generic object which will serve as a proxy for the generic server object
‘ RDSServer.DataFactory

Dim objDataFact As object
Dim connectstr,sqlstr as String

‘Specify the connection information for the ODBC data source on the server ‘which you wish to access
connectstr = "dsn=RMS;uid=;pwd=;"
‘Create a proxy to the RDSServer.DataFactory object on the remote server
Set objDataFact = objDataSpace.CreateObject("RDSServer.DataFactory", "http://a338994")
sqlstr = "Select * from User where UserId = ' " + Sle_UserId.Text + " ‘ and Password = '" + Sle_Password.Text + " ' "

‘Retrieve an ADOR recordset from the remote server by using the ‘Query’ method ‘of the ‘RDSServer.DataFactory object. This recordset should contain the user record of the specified
'user if the entered Id and password are valid.

Set recset = objDataFact.Query(connectstr,sqlstr)
‘The recset object will not contain any record if the details provided in the logon screen are invalid
If recset.RecordCount > 0 Then
‘The NavigateTo method of the HyperLink object is used to activate the ActiveX Document
‘which implements the main interface of the application

HyperLink.NavigateTo << the main interface ActiveX document >>
Else
MsgBox "Invalid Login Details - Please try again !"
Sle_UserId.SetFocus
End If

End Sub

Save the project and the document again after entering the above code segment for the ‘Click’ event of the cmd_OK command button, and exit Visual Basic.

Generating the Internet downloadable setup files for the ActiveX Document project :

The following steps will describe the process of generating the Internet downloadable files for the RlogOn project which contains the LogOnDoc ActiveX document.

  • Start the Visual Basic application setup wizard
  • Specify the following in the ‘Select Project & Options screen’

Project : RlogOn.vbp [ Check the ‘Rebuild Project’ option ]

Options : Select ‘Create Internet Download setup’

  • In the ‘Internet Distribution Location’ screen specify the directory where you wish to have the

Setup files generated

  • In the ‘Internet Package’ screen, select the option ‘Download from Microsoft Site’ for the

Runtime components

  • Click on the ‘Safety’ button, and mark you document as being safe for initialization and

Scripting. These settings are a guarantee for the end user that your component will not harm

their system when downloaded from a web site

  • The ‘ActiveX server components’ screen will list the server components used by the project.

The RDS OLE DB provider, and the Advanced Data Factory DLL’s will be listed on this screen. Select both and click ‘Next’

  • The ‘File Summary’ screen will list all the files that will be used to generate the setup kit for

for RlogOn.vbp. The Visual Basic virtual machine, the ADO DLL’s, and the RlogOn DLL are the key files in this section. Select all files and click ‘Next’.

  • Finally click ‘Finish’ to complete the process. The setup wizard will now generate the Internet

Downloadable setup files which you can upload onto the web server.

 

At the end of this process the following files will be generated :

LOGONDOC.VBD - the internet downloadable ActiveX document

RLOGON.HTML - the HTML file which contains the script to download & display the ActiveX document. The user will specify the URL to this file from within the IE browser, which on loading will display the LOGONDOC.VBD ActiveX document.

RLOGON.CAB – a cabinet file containing a compressed version of the additional files [.DLL’s & the .INF file ] that are required to download and display the ActiveX document. The files used to generate the .CAB file are listed in the SUPPORT directory generated by the setup wizard.

[ Note : Some web servers may not be able to recognize the file extension .VBD, and as a result will end up displaying the contents of such files as binary junk. This can be resolved by changing the extension [ renaming ] from .VBD to .BIN, and modifying the reference to the ActiveX document in the HTML so that it points to the renamed file ]

These are the 3 files which need to be uploaded to the web server in order to make the LogOnDoc ActiveX document available on the web. In RINFO, these files will be uploaded to the same web server on which the application’s Access database is installed.

 

Downloading & Viewing the ActiveX document using Internet Explorer 4.0 :

To view the LogOnDoc ActiveX Document from the IE browser window launch IE4, and

specify the URL for the RLOGON.HTML file installed on the web server

The RLOGON.HTML file which contains the script to activate the LogOnDoc ActiveX document, will be downloaded to the client browser. The script for the Window_OnLoad event in this HTML contains the statements required to download, and display the LogOn ActiveX document in the client browser.

You can now enter a user id and password in this window, and click OK to test if the code connects to the web database and verifies the validity of the information entered.

 

Summary :

The objective of this article is to introduce the readers to the basics of using ActiveX documents to implement the user interface screens of a web database aplication. The ActiveX document technology can be used to develop the interfaces for a web application from scratch, and to migrate existing VB applications to the Internet. The example in this writing illustrates the process of creating an ActiveX document from ground up. In the next article I will address the issue of migrating existing VB applications to the web using this technology.

Further detailed information about ActiveX Documents and their other applications can be found in the ‘Component tools guide’ documentation which ships with the VB5 enterprise and professional editions. This book is a must read for any Visual Basic developer who is serious about Internet and component software development.

 

About the Author :

Karthik Ravindran holds a Masters Degree in Information Technology from the University of East London, and Microsoft certifications in VB & SQL Server. He works for Cognizant Technology Solutions [headquarters in Manhattan, NY ], which is a reputed S/W consultancy firm with a large worldwide client base. Currently he is located at 'Nielsen Media Research' in the city of Dunedin, FL[ a leading Media Ratings organization, and a client of CTS ], where he is responsible for coordinating a series of C/S Year 2000 Impact Analysis & Testing projects. Apart from this he is also leading an internal web database application development effort which uses technologies like MDAC, ActiveX, and VB 5.0. His research interests include web databaseapplication development, and tools for automated S/W testing and QA. He can be reached by e-mail at RavindK@tvratings.com.


Shout! Earn money and Get hits
Shout! Sponsor your site and earn up to 15 cents per click!

Click Here to Visit Our Sponsor

Please visit our sponsors!