ActiveX Control Tutorial - Part 5, Page 2
So, you've finally perfected your wonderful creation. It's flashes, whizzes and whirs - and packs more code than Bletchley Park in 1947.
Now what? Well, we need to distribute the control to our end users.
Thankfully, this part is really easy. In fact, even my pet iguana Strangely Green can do it. You may remember him from the database tutorial. Cute lil' thing.
Am I digressing? Oh, sorry. Well, let's get on and figure out how to distribute your control:
- Launch Visual Basic
- Open the control you wish to distribute, such as the Super Cool Text Box we've been working on over the past few weeks
- Click on File, Make <ProjectName>.ocx
- Select the .OCX location in the dialog box and click OK
After a little cranking of the hard disk, Visual Basic will create your own .OCX file. This is your final control.
Top Tip: An OCX is to your ActiveX control what an EXE is to a standard VB project.
So that's our actual 'EXE' sorted. Before we create the setup program for our end user, let's see our control in action:
> Create a new Standard EXE in Visual Basic
> Select Project, Components
> Find your control in the list, select it and click OK
Top Tip: If your control is called something like 'Project1', you can rename it by reopening your control in Visual Basic, selecting Project/Properties, entering something into the 'Project Description' box and then recompiling the OCX as above.
You should now find your control in the toolbox of your Standard EXE project.
> Add the control to your form
> Try playing with a few properties, methods and events
You should find that your control works just like any other. And if so, that's excellent. Let's continue with our setup program:
- Launch the 'Package and Deployment' wizard, found on the Start menu (usually within the Visual Studio or Visual Basic Program folders)
- Select your .VBP ActiveX control project after clicking the 'Browse' button
- Hit the 'Package' icon
- If asked if you want to recompile your OCX file, select 'No' we did that just a few minutes ago
Now it's time for the wizard to step in. Follow the prompts through to the end. Note that:
- On the 'Cab Options' screen, select 'Multiple Cabs' if you're going to distribute via floppy disk, or 'Single Cab' if you're going to dish out via CD-ROM or as a zipped up download from the Internet
- On the 'Installation Title' screen, enter the title of your project such as 'Super Cool Text Box'
- If you want to save your setup settings for a later session, enter a script name on the 'Finished!' screen
Most of the time, you'll be fine just accepting the defaults. But be sure to read the explanations and change anything you desire.
- When you've cycled through all the wizard screens, hit Finish
- After your machine stops buzzing, read the brief status report then click Close
That's it! You've just created a setup package for your control, ready to be distributed to your end users!
Try checking out the folder in which the wizard placed your setup files. You did make a note of it, right? It's probably called 'Package'.
Try copying these files across to a different computer, running the Setup program (setup.exe) and trying out your control within Visual Basic, Excel or whatever. It should work just the same as it does on your computer!
Well done! You've just created and tested a setup package for your control!
In fact, you'd better keep those test setup disks. They'd make an ideal Christmas present for any self-respecting nerd.
Important Top Tip: Now that you've compiled your control, it isn't just restricted to use within Visual Basic. You could utilise it within Excel, Word, Internet Explorer, Visual C++ or any ActiveX-aware application!