| Purpose | With the CallVB statement, you can call .NET functions from a GuiXT script or InputScript –
regardless of whether these are implemented in C#, VB.NET, or another .NET language. In the called function you can
The .NET class library (dll) can be made available locally or centrally, e.g. in the SAP MIME Repository Prerequisites:
|
| Example | CallVB msg =
utilities.email.send The .NET class library "utilities.dll" is loaded from the ".NET class libraries" folder specified in GuiXT profile, guixt.ini-Parameter VBDirectory. For each SAP GUI mode a separate object of the given class "email" is created. The function "send" of this object is called and the function result is stored in V[msg]. |
| Format 1 | CallVB
progname.classname.funcname
"par1" "par2 "par2" ... The class library progname.dll is loaded and for each SAP GUI mode a spearate object of class classname is created. The function f of this object is called, passing the given strings "par1", "par2",... as function parameters. Instead of passing the parameters as position parameters, you can also specify the parameter names defined in VB. Example: CallVB utilities.email.send emailaddr:="&V[email]" cc:="&V[cclist]" subject:="&V[subject]" body:="&V[mytext]" |
| Format 2 | CallVB
varname
= progname.classname.funcname "par1" "par2 "par2" The class library progname.dll is loaded and for each SAP GUI mode a spearate object of class classname is created. The function f of this object is called, passing the given strings "par1", "par2",... as function parameters. The function result is transformed into a string and set into the given GuiXT variable V[varname]. |
| Processing details |
The first
CallVB
command for a class library "progname.dll"
loads the library into the .NET runtime. If necessary, the library is
first copied from the SAP MIME Repository into the local GuiXT cache
folder. If you use the SAP MIME Repository, please set a VersionNumber in the session script. The interface libray guinet.dll is also copied, if necessary, Next an object of class classname is created, one for each SAP mode, and the given function funcname of this object is executed. All parameters are passed by value and in string format. The returned value is transformed into string format and stored into the given GuiXT variable. In the called VB function you may read and write GuiXT variables and longtext variables; for details see Class "guixt" in VB. Passing parameters "by reference" is not supported but you may simulate this by passing the name of a variable and the use guixt.GetVariable() and guixt.SetVariable(). |
| Conversion of values | If a .NET function declares its parameters as scalar types other than String (e.g., Integer, Decimal, Double, or Date), GuiXT automatically performs a conversion from the GuiXT string to the target type when the function is called. Technically, this is done within the .NET environment using the CTypeDynamic method.
GuiXT automatically converts scalar return types into a string. In this process, "Boolean" is returned as "-1" for True and "0" for False. Regional settings of the user affect date values and decimal numbers. Recommendations for typing:
Example with automatic conversion:
Example with custom conversion (recommended):
GuiXT
The result returned is "1.4142135623731". |
| Object references |
Object references can be used
as function parameters and can be returned by the VB function. GuiXT
uses a string representation of the object references and automatically
converts these string parameters to VB object references and
converts a returned object reference to a string. Technically "IDispatch"
interface pointers are used here. You can pass an object reference to a
second VB function and then use the object's methods and attributes.
Example: In the VB.NET-Funktion "newcustomer" we create a new object of class "customer" and return the object reference to GuiXT:
In GuiXT we call the first function and store the result into a variable. Later on we can call up the second function and pass the "customer" object: GuiXT
Now the variable V[name] contains the string "abc GmbH". |
| Handling of .NET Exceptions | When calling a .NET method, an exception (error causing termination of the CallVB) can occur at various points:
In all cases, GuiXT sets the return value to "" and generates an error message in the "Script" window, the InputScript trace, as well as in the GuiXT Script Editor Pro, but continues processing the script. After CallVB, you can check with if not Q[ok] whether an exception has occurred; the corresponding error text is then available in the system variable V[_exception]. Here are some examples: GuiXT
Message: "Method 'sqroot' not found in class 'calculations' of dll C:\GuiXT\VB\util.dll" GuiXT
Message for parameter type "Double": "VB.NET Exception for parameter 'n': The input string has an incorrect format. Conversion from string "abc" to type 'Double' is not valid." Message for parameter type "String" with custom conversion: "VB.NET Exception: The input string has an incorrect format." You can also perform your own validations in the .NET method and then trigger an exception with a custom-defined message using "Throw":
GuiXT
Message: "VB.NET Exception: Invalid value passed to method util.sqrt: abc" |
| Debugging | You may
use the "Stop" command in your VB.NET function to start the
Visual Studio debugger. Alternatively, you can use the "Debug->Attach to process" function for the "saplogon.exe" process in order to activate debugging dynamically for a running SAP session. |
| Example 2 | We start
MS
Excel with some demo values:
|
| .NET and Javascript | In the tutorial Advanced: JS, .NET, WASM, you will learn how to integrate .NET with other technologies (JavaScript and WASM) in GuiXT applications. |
| Tips & Tricks | |
| Components | GuiXT + Controls |