0

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 ?

Dah Sra
  • 4,107
  • 3
  • 30
  • 69
  • Can you clarify what you mean by "VBScript that contains reference of other scripts"? I'm not familiar with a general include mechanism for VBScript. WSH allows for loading multiple files to run, but I don't think that's what you're referring to. –  Nov 28 '17 at 13:47
  • @PeterCooperJr. to use functions of other scripts we need to include that script name in top as reference na that one.(eg) !INC Local Scripts.Constants-VBScript – Dah Sra Nov 29 '17 at 04:13
  • I've never heard of "!INC" as a VBScript command. I suspect that you're either using some other technology you haven't told us about, or you're confusing VBScript with some other language that uses that syntax for file inclusions. VBScript doesn't have an include command. –  Nov 29 '17 at 13:01
  • @PeterCooperJr. Yes am using VB in Enterprise Architect tool – Dah Sra Nov 29 '17 at 16:11

1 Answers1

2

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.

Geert Bellekens
  • 12,788
  • 2
  • 23
  • 50