Click to See Complete Forum and Search --> : Using script control


damian_666
May 10th, 2001, 06:33 AM
I need some help.
I need to throw event from one VBScript
and the script control in my proyect must
caught this event and execute some code at
then time the event occurrs
how can i throw this event and
how can i caught it?
thank you very much
please mail me at damian_666@mixmail.com

Cakkie
May 10th, 2001, 09:07 AM
Theres no real way to cast an event in the scriptcontrol, however, they wouldnt call us gurus if we couldnt find a way around this.

The idea is simple, add a class module to your project (class1). Declare a public event (myEvent). Declare a public sub called RaiseMyEvent.
Now, the scriptcontrol allows us to pass objects to the scripts inside. You can do this with the AddObject method (or something) of the scriptcontrol object. This take some arguments, one of them is the object you are passing, another is the name by which the script can use it. This object we are passing is our class1, which must be declared withevents. Thisway we can catch the events the RaiseMyEvent method of the class raises, which is called by the script.

' class 1
public event myEvent()
public sub RaiseMyEvent()
RaiseEvent myEvent
end sub

' our form
private withevents myClass as Class1

private sub form_load()
set myClass = new Class1
scriptcontrol1.addobject class1,"thisclass"
end sub

private sub myClass_myEvent()
msgbox "the event has been raised"
end sub



If the code in the scriptcontrol now calls thisclass.raisemyevent, the event should be raised.
I'm not sure about the example i've given, because i don't have my stuff here, so don't shoot me if i got some functionname incorrect or so.
One thing i can assure you that it is possible.

Tom Cannaerts
slisse@planetinternet.be

Programming today is a race between software engineers striving to build bigger and better idot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook