Purpose
Decide between using JavaScript, VBScript, VB.NET or C# for a particular task
.

GuiXT provides interfaces to the programming languages JavaScript and VBScript and to all .NET languages such as VB.NET or C# . These interfaces allow us to implement our own functions if no suitable GuiXT keyword is available that fulfills a particular task. Before starting the implementation we need to decide which language we want to use.

Recommendations

1. Prefer JavaScript to VBScript in new projects

VBScript is now called a "legacy programming language" by Microsoft whereas JavaScript is recognized as the leading Web programming language.

MS Visual Studio supports the debugging of JavaScript functions very well;  VBScript debugging is no longer supported.

2. You may keep your existing VBScript functions

But install GuiXT version 2019 Q3 3 or above in this case.

In previous versions GuiXT uses the "Microsoft browser control" to run the VBcript engine. This browser control can emulate different Internet Explorer modes IE7 (default) to IE11, depending on a registry setting "FEATURE_BROWSER_EMULATION" which is valid for the whole SAP GUI process. If the setting is IE11, VBScript is not available and your CallVBS statement does not find the called function. The IE mode of the browser control can be set to IE10 with ProcessingOption ie_browser_emulation="10001". But this does not work in a running SAP GUI process if another SAP function has already set the mode and has created a browser control.

The conversion of existing VBScript functions to JavaScript, if you decide to do so, can be accomplished with moderate effort. For example,

Function start_excel()
  Dim XL
  Set XL = guixt.CreateObject("Excel.Application")
  XL.Visible = True
  XL.Workbooks.Add
End Function

is changed to
function start_excel()
{
    var XL = guixt.CreateObject("Excel.Application");
    XL.Visible = true;
    XL.Workbooks.Add();
};

There are some caveats:
  • JavaScript is case-sensitive, VBScript is not case-sensitive.
  • Do not use "new ActiveXObject" in JavaScript, use "guixt.CreateObject" instead.

  • JavaScript, in contrast to VBScript, operates in a "sandbox" and does not allow  access to the local PC, for example to read and write local files. This makes sense since JavaScript is normally used in a browser connected to the internet and we want to protect our PC against malicious code.

    When called up from GuiXT the interaction with local files, Excel, Word,... makes sense. This is possible by creating the right ActiveX object for such actions, for example  "Excel.Application", "Shell.Application", ... Remember that you need to create them with guixt.CreateObject()

  • Some native VBScript string functions are not available in the JavaScript language, but for all of them JavaScript substitutes can be implemented, see e.g.
    VBScript-to-JavaScript Functions

 

3. JavaScript or .NET (VB.NET / C#)

Both choices can make sense, depending on the project type:

  • For large projects, VB.NET is the superior language due to its strict typing, modularity, and rich infrastructure with lots of useful classes

  • If JavaScript is sufficient for a particular task, for example for automating Excel or for scripting an embedded HTML page, it is a reasonable lightweight approach, especially if you are already familiar with JavaScript from web projects

  • A mixture of both languages (calling each other) is possible but increases overall complexity

  • Performance:
    The overhead of a JavaScript call is less than that of a VB.NET call, but both technologies are fast enough for all normal scripting tasks.  We measured an InputScript that executed 100 000 simple calls, passing two small strings and returning a small string, on a modern PC (3.6 GHz Intel CPU); this took around 3 seconds with JavaScript and 12 seconds with VB.NET.
    The difference is mainly due to the fact that calling .NET from GuiXT requires the transition between a "managed" and  an "unmanaged" environment.

 

4. VB.NET or C#

Our .NET samples here are mostly written in VB.NET, but it is completely up to you to use C# instead of VB.NET.

When you translate existing VB code to C#, keep in mind that C# is case sensitive.

 

Components
InputAssistant + Controls