executing vbscript functions from a C# winform app

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kasper

    executing vbscript functions from a C# winform app

    Hi Group.

    I have an old VB6 application which loads a number of gui controls
    from an inifile and for each control the inifile states the name of
    the vbscript that should be executed once the control is clicked or
    otherwise triggered.
    My question is whether it is possible to execute the vb scripts from
    C#? There are multiple scripts in the same file.

    If that is not possible I sure would like a hint about how I create a
    winforms app where the eventhandler is defined at runtime, not
    compiletime.

    TIA

    Kasper
  • Marc Gravell

    #2
    Re: executing vbscript functions from a C# winform app

    Well, the simplest way is to store something useful in the tag, and
    simply have a shared handler, i.e.

    private void foo_Clicked(obj ect sender, EventArgs args) {
    Control cont = sender as Control;
    if(cont!= null) {
    // do something with cont.Tag
    }
    }

    Then when looping:

    foreach(whateve r) {
    SomeControl foo = new SomeControl();
    // init
    foo.Tag = {something useful}; // could also use Name I suppose
    foo.Clicked += foo_Clicked;
    }

    Depending on needs, you can do things a lot more sophisticated.

    Marc

    Comment

    • Marc Gravell

      #3
      Re: executing vbscript functions from a C# winform app

      (you'll also need to add each "foo" onto the form somewhere ;-p)

      Marc

      Comment

      • Nicholas Paldino [.NET/C# MVP]

        #4
        Re: executing vbscript functions from a C# winform app

        Kasper,

        I think that the best option here is to refactor the VB6 app so that the
        UI is contained in hostable ActiveX controls and then host those controls in
        your C# app, and let the VB6 code that is being interoped with handle the
        script (as you were before).

        --
        - Nicholas Paldino [.NET/C# MVP]
        - mvp@spam.guard. caspershouse.co m

        "Kasper" <kasperbolarsen @gmail.comwrote in message
        news:ebf62ba0-6e16-4d68-a086-be9cd8719f76@q7 7g2000hsh.googl egroups.com...
        Hi Group.
        >
        I have an old VB6 application which loads a number of gui controls
        from an inifile and for each control the inifile states the name of
        the vbscript that should be executed once the control is clicked or
        otherwise triggered.
        My question is whether it is possible to execute the vb scripts from
        C#? There are multiple scripts in the same file.
        >
        If that is not possible I sure would like a hint about how I create a
        winforms app where the eventhandler is defined at runtime, not
        compiletime.
        >
        TIA
        >
        Kasper

        Comment

        Working...