VB Script with reference script is not working in ScriptControl c#

721 views Asked by At

Hi I am executing a VB script using script control in c#. If it is a standalone script then it works fine for me by using the below code.

            ScriptControl SC = new ScriptControl();
            SC.Language = ScriptType;
            SC.AddObject("Repository", RP);
            SC.AddCode(scriptcontents);
            Object[] runobject = { };
            string result = SC.Run(ScriptName, runobject);

But when i tried to run a VBScript that contains reference of other scripts then its not executing in the script control and throws error. Referencing other scripts in a script by

!INC Local Scripts.Constants-VBScript

Is there any way to add reference scripts of a script in script control ?

1

There are 1 answers

0
Geert Bellekens On BEST ANSWER

VBscripts in Enterprise Architect have a few "extensions" that are problematic when executing it via a generic scripting host.

  • Includes: EA uses the syntax !INC <scriptGroup>.<ScriptName> to include other scripts. This is however an EA specific syntax that is not known to other script interpreters. In order to avoid this you can replace the include statement the whole code of the included script.
  • Variable typing: In EA scripts you can write something like Dim myVar as EA.Element this is very useful in the EA script editor because it allows for code completion, but the syntax is not known to any other script interpreter. These type declaration should be removed.
  • Session and Repository: In EA you can use the Session and Repository object without defining it. If you want to execute a script using the ScriptControl then you'll have to add those as an object. For Repository this can be done using scriptController.AddObject("Repository", eaRepository);

For a complete working example see The Enterprise Architect Add-in Framework on Github.
This code reads the scripts from the model and MDG's, takes care of includes, and adds the Repository object.
It doesn't handle variable typing and the Session object.