Click here to Skip to main content
11,802,442 members (70,499 online)
Click here to Skip to main content

How to write an updatable ActiveX control for web page in VB6

, 10 Sep 2004 136.3K 2.6K 38
Rate this:
Please Sign up or sign in to vote.
This article will explain how to write an embeddable ActiveX control to use in a web page, that can be updated and reinstalled from the web page.


Many times, you may need to use a powerful COM-based control in your web application that might need to be modified at a later date. In some cases, it is sufficient to simply reference the .ocx file (<OBJECT CODEBASE="myActiveXcontrol.ocx" />). However, this method will not work if the code for the control needs to be modified and reinstalled on the user's machine.

Instead, a better method will utilize Visual Studio's Package and Deployment Wizard to create a CAB file that serves as a direct installation (or reinstallation) of the .ocx which can be referenced in the <object> tag.

Step 1: Create the Control in Visual Basic

As an example, we will first create a simple control in VB 6.0.

Open MS Visual Basic, and choose "ActiveX" control:

Main Screen

I then placed two components on my control- a Command button, called cmdTest, and a text box, called txtTest:

dev Screen

(This a very simple example, just to show how a web client script interacts with an embedded ActiveX control).

Next, we will write some code to test our functionality. Our goal is to pass a value to the text box from our web page, then use the command button to display that text in a message box. We will need the code for the _click() and a Public function to populate the textbox (we need it public so that it can be accessed outside of the scope of the VB control, i.e., the web page code). I use the function setText() to accomplish this:

Public Function setText(txt As String)
    txtTest.Text = txt
End Function
Private Sub cmdTest_Click()
    MsgBox txtTest.Text
End Sub

Step 2: Package the Project

Next, we will need to save, make, and package our project. My project is called vbActiveX, and my control is called ctlVBAX. Click on Tools-->Package and Deployment Wizard. Click Package at the main screen. (It may ask you to re-compile and/or save your project. Just click Yes.)

Follow the screen shots as so:

Sample screenshot

Sample screenshot

Sample screenshot

Your package should exist now in /Package within your project folder.

Step 3: Write the web page code

Our last step involves adding the client side script on our web page, as well as some HTML to interact with the embedded ActiveX control.

I simply created a dropdown called "drpValues", and gave the options "value1"-"vaue5". Our goal is to populate the textbox on the AX control (txtTest) with the value selected from the dropdown. We will need to add a JavaScript function to accomplish this:

<select id="drpValues" onclick="send_value(this)">
 <option value=""></option>
 <option value="value1">value1</option>
 <option value="value2">value2</option>
 <option value="value3">value3</option>
 <option value="value4">value4</option>
 <option value="value5">value5</option>
<--this goes into the <head></head>

Notice the <object> tag, and what it holds:


As you can see, the object ID is ctlVBAX, and this is what we refer to when using in our script. Also notice that the CODEBASE portion includes the .CAB file, not the .ocx, so the system looks to the version of the CAB to initialize the ActiveX control. If it is a newer version, it will update the control, almost like a re-installation.

Test the page by opening up vbActiveX.HTM inside the /Package folder.

To test the updating, change a few things in the ActiveX control code, and re-make the project (File->Make). Then, copy the new .ocx from your main project folder into the /support directory, and use the batch file there to re-make the CAB file in /Package. Finally, copy that CAB file back into your project folder, and re-open the web page. You should notice that the changes have taken.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Matt Sciotto
Web Developer
United States United States
Matt Sciotto is an IT professional, who specializes in VB and .Net software/web application development. He has written several embeddable ActiveX COM controls, as well as custom server controls in VB.Net, and many scalable webform applications. In addition, he has a handy background in server scripting including knowlege of PHP,Perl,CGI and ASP, and Database Management with intense SQL foundation in MS SQL Server, MS Access, Oracle and MySql environments. He has worked on several OS platforms including all recent versions of Windows, Red Hat Linux, FreeBSD, UNIX and Solaris.

You may also be interested in...

Comments and Discussions

QuestionI can't get it to work right! [modified] Pin
MulleDK1314-Oct-07 5:48
memberMulleDK1314-Oct-07 5:48 
QuestionRe: I can't get it to work right! Pin
Wilson tEN9-Sep-08 19:35
memberWilson tEN9-Sep-08 19:35 
AnswerRe: I can't get it to work right! Pin
adolfogh7-Oct-08 22:04
memberadolfogh7-Oct-08 22:04 
Questionactivex control activation Pin
todevesh3-Oct-07 22:37
membertodevesh3-Oct-07 22:37 
QuestionYour Method Doesn't worked Pin
goldenrose925-Sep-07 10:53
membergoldenrose925-Sep-07 10:53 
QuestionMore than one OCX in a web page Pin
chewkokhooi13-Jul-07 18:19
memberchewkokhooi13-Jul-07 18:19 
GeneralQuestion for local access. Pin
eric feng2-Mar-07 8:12
membereric feng2-Mar-07 8:12 
GeneralI m not getting the ActiveX control Contents Pin
bhavna81622-Feb-07 0:22
memberbhavna81622-Feb-07 0:22 
GeneralMy changes aren't being displayed Pin
alexsd4-Jan-07 11:12
memberalexsd4-Jan-07 11:12 
GeneralThank you Pin
Mr.No31-Jul-06 4:22
memberMr.No31-Jul-06 4:22 
Generalonly works with administrative permissions [modified] Pin
bobnob19-Jun-06 22:20
memberbobnob19-Jun-06 22:20 
GeneralService pack 6 for visual basic 6.0 cabinates install message Pin
plmanikandan7-Jun-06 4:11
memberplmanikandan7-Jun-06 4:11 
GeneralI found it finally, but there is a big problem. Pls help... Pin
tduccuong12-Dec-05 14:59
membertduccuong12-Dec-05 14:59 
GeneralRe: I found it finally, but there is a big problem. Pls help... Pin
qcha0s6-Jan-06 17:49
memberqcha0s6-Jan-06 17:49 
QuestionHow can I create such a control with VB.NET Pin
Manoj Prajapati17-Oct-05 19:20
memberManoj Prajapati17-Oct-05 19:20 
GeneralThis is there and everyone is using it Pin
Anonymous13-Oct-05 19:18
sussAnonymous13-Oct-05 19:18 
GeneralOcx Dependency Pin
Vasudevan Deepak Kumar1-Aug-05 20:41
memberVasudevan Deepak Kumar1-Aug-05 20:41 
GeneralGreat Info Thanks Pin
Pinhead_Me27-Oct-04 13:31
memberPinhead_Me27-Oct-04 13:31 
GeneralRe: Great Info Thanks Pin
Anonymous23-Aug-05 0:21
sussAnonymous23-Aug-05 0:21 
GeneralThanks Pin
Pops4718-Oct-04 17:22
memberPops4718-Oct-04 17:22 
GeneralSecurity Settings Pin
sandeepk199920-Sep-04 5:38
membersandeepk199920-Sep-04 5:38 
GeneralRe: Security Settings Pin
mittalsumit29-Aug-06 2:23
membermittalsumit29-Aug-06 2:23 
GeneralVB6 runtime Pin
Lars [Large] Werner11-Sep-04 22:19
memberLars [Large] Werner11-Sep-04 22:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.151002.1 | Last Updated 10 Sep 2004
Article Copyright 2004 by Matt Sciotto
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid