You implement a method for your ActiveX control in pretty much the same way
that you implement methods for other ActiveX components and for classes in general. As mentioned
above, custom methods for an ActiveX control are implemented as Public Procedures in the
UserControl object.
If, for example, you wanted to give your developers an Alarm method for the
control you are developing, you would put code similar to the code of Listing 13.4 into your
UserControl's code.
LISTING 13.4
CODE FOR A CUSTOM CONTROL METHOD
Public Sub Alarm(Optional Severity)
'If the alarm is more
severe,
'then beep more times
If IsMissing(Severity) then
Severity = 1
Dim iCount As Integer
For iCount = 1 To Severity
Beep
Next iCount
End Sub
Assuming that your developer has created an instance of your control named
"MyControl" in a project, then the developer could write a line of code such as
MyControl.Alarm 7
NOTE - Using an Optional Variant Parameter : Notice
that our example method takes an Optional parameter. We've let the parameter's
type default to Variant so that we can check for its existence with the IsMissing
function (recall that IsMissing only works properly
on Optional parameters of Variant type).