Posted on 2000-03-03
Medium Priority
Last Modified: 2013-11-26
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).

Question by:hpet
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
LVL 10

Accepted Solution

caraf_g earned 400 total points
ID: 2579627
"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

LVL 10

Expert Comment

ID: 2579629
Sorry, that should read:

"To each new instance of Form1, Class1 hands that single instance of the event handler class"

Author Comment

ID: 2579885
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?

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

LVL 10

Expert Comment

ID: 2580278
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!

LVL 10

Expert Comment

ID: 2580284
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


Author Comment

ID: 2580884
Adjusted points to 100

Author Comment

ID: 2580885

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.
LVL 10

Expert Comment

ID: 2580992
Sorry, don't know anything about that. If noone here can help you maybe you could try the newsgroups. Some good ones:

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month14 days, 2 hours left to enroll

800 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