[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 220
  • Last Modified:


I have program module as ActiveX DLL.
Now I have wish to run multiple independed instance of that module.
I access DLL through multiuse class which based of input parameters serves
main programs wish (like what exactly to load).
Let's that there is Form1 in DLL. When I call method in class from main program requesting
Form1 to load I creat new Form1.
Set frm = new Form1
Now each form works in its own space.
So far so good, but now I want some response (as needed) back from Form1 to main program.
Therefore I used events. I raise event which causes event in class, then that class raises
event again in order to pass this event futher back to main program.
So far so good, but only last instance of Form1 can do that.
Other previous instances fire event, but event doesn't happen in class.

What am I doing wrong or how should I do it right?
Currently main program creates only once instance of that class and that class then creates multiple forms (for example).

  • 5
  • 3
1 Solution
"Currently main program creates only once instance of that class and that class then creates multiple forms (for example). "

That's where your problem lies.

What you could do is have an event handler class.

Class1 creates one instance of event handler class

Class1 creates multiple instances of Form1

To each new instance of Form1, Class1 hands an instance of the event handler class.

The eventhandler class has a sub that can be called by form1. Where you want form1 to raise an event, let it call the sub in the eventhandler class instead.

Then let the eventhandler class raise an event.

Finally, Class1 can then respond to the event.

The parameters of the event handler's event should be such that they allow you identify the originating instance of form1.

Hope this helps

Sorry, that should read:

"To each new instance of Form1, Class1 hands that single instance of the event handler class"
hpetAuthor Commented:
Thanks caraf_g for fast reply.
I am just trying to implement your suggestion. I created event handle class with HandleEvent sub.
I create one instance of Class1 and then Class1 creates possible multiple Form1.

How do Class1 hand that single instance of event handler class to current Form1 instance?

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Let's say your event handler is called

Simplest solution:
In your form, declare a public variable

Public objEventHandler As clsEventHandler

In Class1

Private WithEvents mobjEventHandler As clsEventHandler

Private Sub Class_Initialize()

Set mobjEventHandler = New clsEventHandler

End Sub

Private Sub Class_Terminate()

Set mobjEventHandler = Nothing

End Sub

When it instantiates a form

Dim frm As YourForm
Set frm = New YourForm
Set frm.objEventHandler = mobjEventHandler

In the form, when you want to raise the event
objEventHandler.RaiseThatEvent(Me, etc...)

In clsEventHandler:

Public Event ThatEvent(objForm As YourForm, any other parms)

Public Sub RaiseThatEvent(objForm As YourForm, any other parms)

RaiseEvent ThatEvent(objForm, any other parms)

End Sub

And finally, in Class 1

Private Sub mobjEventHandler_ThatEvent(objForm, any other parms)

'Do what you have to do to objForm

End Sub

Hope this helps!

For completeness sake...

In YourForm

Private Sub Form_Terminate()

set objEventHandler = Nothing

End Sub

.... And put some checking code in

If Not objEventHandler Is Nothing


just in case someone forgets to code the last line of
Dim frm As YourForm
Set frm = New YourForm
Set frm.objEventHandler = mobjEventHandler
when they instantiate the form

hpetAuthor Commented:
Adjusted points to 100
hpetAuthor Commented:

Thanks, you were realy helpful.
Simple solution all together... now that I see it. Too little sleep I guess. Good thing weekend is comming up.

I increased points to 100... thanks


P.S. btw, I am trying to find something out about MSDE data engine. Are you familiar with it? I posted questions few times but nobody even touched it :(
Question is not realy realted to MSDE only. They suggest 5 or less concurrent users before its performance will start degrading. That "concurrent" is realy what I am after, what does it mean exactly for MSDE. Does it mean client connections, does it mean number of simultaneous tasks in MSDE, etc.
Sorry, don't know anything about that. If noone here can help you maybe you could try the newsgroups. Some good ones:

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now