Solved

Events...

Posted on 2000-03-03
8
214 Views
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
frm.show
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).

thanks,
hpet
0
Comment
Question by:hpet
  • 5
  • 3
8 Comments
 
LVL 10

Accepted Solution

by:
caraf_g earned 100 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

pino
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 2579629
Sorry, that should read:

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

Author Comment

by:hpet
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?

hpet
0
Independent Software Vendors: 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!

 
LVL 10

Expert Comment

by:caraf_g
ID: 2580278
Let's say your event handler is called
clsEventHandler

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!

0
 
LVL 10

Expert Comment

by:caraf_g
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


0
 
LVL 1

Author Comment

by:hpet
ID: 2580884
Adjusted points to 100
0
 
LVL 1

Author Comment

by:hpet
ID: 2580885
caraf_g,

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

hpet

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

Expert Comment

by:caraf_g
ID: 2580992
Sorry, don't know anything about that. If noone here can help you maybe you could try the newsgroups. Some good ones:
news.devx.com
msnews.microsoft.com
0

Featured Post

Independent Software Vendors: 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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
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 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…

713 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