Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Implement an event in vb6?

Tags:

events

vb6

I have defined one button and one event am raising the event in button click so my question is how to implement that event

Public Event ClickEvent()

Private Sub Command1_Click()
    RaiseEvent ClickEvent
End Sub
like image 653
superuser Avatar asked Oct 18 '25 20:10

superuser


1 Answers

Assuming your code as posted is in a Form called Form1.

Create a new Form (Form2). Add this code to Form2:

'declare an object and tell vb you want to subscribe to the objects events
Private WithEvents Foo As Form1

Private Sub Form_Load()
    'initialise the object
    Set Foo = New Form1
    'show the Form1 object which has the button on so we have something to click
    Foo.Show
End Sub

'when the button is clicked this event is raised
Private Sub Foo_ClickEvent()
    MsgBox "Click Event"
End Sub
like image 148
Matt Wilko Avatar answered Oct 22 '25 05:10

Matt Wilko