Book a Demo

Author Topic: Calling VBScript from JScript  (Read 3132 times)

M1TO

  • EA User
  • **
  • Posts: 22
  • Karma: +0/-0
    • View Profile
Calling VBScript from JScript
« on: July 12, 2023, 06:50:22 pm »
Hello all!

I want to call a script written in VBScript from a script written in JScript. Is there a way to do this?
In JScript one would use the "!INC" Statement and then call the function from the file included. But this doesn't work with a VBScript script and function.

cheers

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13495
  • Karma: +572/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Calling VBScript from JScript
« Reply #1 on: July 12, 2023, 07:21:03 pm »
No, not easily.

You can execute VBScript code, but you would have to do it with an eval.

There is an example of that in the standard scripts.

Code: [Select]
function DLGInputBox( promptText /* : String */, title /* : String */, defaultText /* : String */ ) /* : String */
{
// JScript has no intrinsic InputBox method, therefore we have to steal VBs
var vbe = new ActiveXObject("ScriptControl");
vbe.Language = "VBScript";

return vbe.eval( "InputBox(\"" + promptText + "\",\"" + title + "\",\"" + defaultText + "\")");
}

A problem with this is the fact that a lot of the code is not standard VBScript. Things like "as EA.Element" and !NC are not standard VBScript, and are removed or replaced by EA before actually being executed.

So you would need vanilla VBScript in order to make this work at all.
If you wanted to use Repository or Sesion, you would have to add that to the context of the scriptcontrol as well before executing the code.

Another issue is that this will only work in 32 bit. There is a solution for 64 bit, but that requires a custom components such as https://github.com/tablacus/TablacusScriptControl

Geert

M1TO

  • EA User
  • **
  • Posts: 22
  • Karma: +0/-0
    • View Profile
Re: Calling VBScript from JScript
« Reply #2 on: July 12, 2023, 08:04:14 pm »
Thanks Geert for the reply.

I know the MessageBox example, but this is not what I need. There is a VBScript in EA and I want to call functions of it from my JScript script. Otherwise, I'd have to translate the script into JScript.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13495
  • Karma: +572/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Calling VBScript from JScript
« Reply #3 on: July 12, 2023, 09:28:11 pm »
Thanks Geert for the reply.

I know the MessageBox example, but this is not what I need. There is a VBScript in EA and I want to call functions of it from my JScript script. Otherwise, I'd have to translate the script into JScript.
I figured that, hence the "No, not easily" in my reponse. ;D

Practically speaking I'm afraid the only option is to translate one of the two scripts.

Geert

M1TO

  • EA User
  • **
  • Posts: 22
  • Karma: +0/-0
    • View Profile
Re: Calling VBScript from JScript
« Reply #4 on: July 12, 2023, 09:36:41 pm »
 :'( Never an easy solution.  ;D