CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2001
    Posts
    7

    Using script control

    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 [email protected]


  2. #2
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: Using script control

    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
    [email protected]

    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
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured