Events in class

Posted on 2003-03-16
Medium Priority
Last Modified: 2010-04-07
In my activeX dll project, I have the class as say class1.cls and a form say form1 with label1
from class1, i show the form from one function
i've declared one public event as 'gotClicked'
now what i want is when user clicks on label1 in form1 my gotClicked event [declared in class1] should be raised

Thank u

Question by:avya2k

Accepted Solution

happel earned 225 total points
ID: 8150061
In class1:
Public Event gotClicked()

Friend Sub RaiseAnEvent()
    RaiseEvent gotClicked
End Sub

Private Sub Class_Initialize()
    Set myClass = Me
End Sub

Public Sub Start()
    Dim mForm As Form1
    Set mForm = New Form1
    Call Load(mForm)
    Call mForm.Show(vbModal)
    Set mForm = Nothing
End Sub

In module1
Public myClass As Class1

In Form1
Private Sub Label1_Click()
    Call myClass.RaiseAnEvent
End Sub

Compile project (ActiveX DLL)

Start new 'Standard exe' project, rename project name to something else than 'project1'
Add reference to your new DLL

and add code

Private WithEvents myClass As Project1.Class1

Private Sub myClass_gotClicked()
    Call MsgBox("Clicked")
End Sub

Author Comment

ID: 8150820
That's very nice
i had tried the same way but failed due to minor mistake of declaration
but anyway ,that ehlped me a lot
Thanks a lot

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question