Solved

Events...

Posted on 2000-03-03
8
210 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
 
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

708 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now