VB6 beginners tutorial - Learn VB6

Advanced VB6 tutorial - Learn Advanced VB6

Systems Analysis - System analysis and Design tutorial for Software Engineering

You are here: Visual Basic > Advanced VB6 tutorial > Chapter 13

Implementing Custom Methods

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.


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
   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).


<< Previous | Contents | Next >>

Home | About Us | Privacy Policy | Contact Us

Copyright © | All Rights Reserved