Many ActiveX controls cannot be freely distributed
to end users but instead require a license before
the system will allow them to be used in applications.
VB will raise a runtime error if an ActiveX
control requires a license key and you attempt
to add an instance of that ActiveX control to
the Controls Collection without providing the
license key (see Figure 4.19).
FIGURE 4.19 A runtime error caused by the
lack of a license key for an ActiveX control
added to the Controls Collection.
To provide a license key to the runtime environment,
you must determine the contents of the key and
then add the key to the Licenses Collection
before trying to add an instance of the control
to the Controls Collection. Add the key to the
Licenses collection with a call to its Add method
using the following syntax:
Licenses.Add Controltype, LicenseKey
where ControlType is the string representing
the control's ProgID and LicenseKey is
the string representing the license key for
that type of control.
So how do you find out the license key for
a particular control type? In your development
environment, you can make a call to Licenses.Add
that automatically adds the control's
License key to the Licenses Collection without
having to know the License key beforehand, and
at the same time provides the license key in
a string that you can examine. The syntax for
such a call would be:
StrLicenseKey = Licenses.Add(ControlType)
where strLicenseKey is a string variable that will
hold the license key for the control type. When you run this line in your development
environment, you can then examine the contents of strLicenseKey (using a
Debug.Print message or some other display technique) to find out the contents
of the license key for that control type.
When you release your product to end users, you can change your code to the
first syntactic format listed above to allow your application to load the control
on the user's workstation. You would hardcode the key that you discovered as the
second argument to the Licenses.Add method.
Adding and Deleting Controls Dynamically Using the Controls Collection