Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

New Post: vbs events

$
0
0
Hi again,

Suppose you have a .NET class with an event:
publicclass Foo {
    publicevent EventHandler SomethingHappened;
    publicvoid MakeSomethingHappen() {
        if (SomethingHappened != null)
            SomethingHappened(this, new EventArgs());
    }
}
Here's how you might handle the event in VBScript code:
engine.AddHostObject("foo", new Foo());
engine.AddHostType("Console", typeof(Console));
engine.Execute(@"
    sub OnSomethingHappened(sender, args)
        Console.WriteLine(""Something just happened!"")
    end sub
    set connection = foo.SomethingHappened.connect(GetRef(""OnSomethingHappened""))
    foo.MakeSomethingHappen()
    connection.disconnect()
");
Good luck!

Viewing all articles
Browse latest Browse all 2297

Latest Images

Trending Articles





Latest Images