Purpose With CallVB you can call a VB function from a GuiXT Script or InputScript.

In the called function you can

  • use the function parameters (strings or objects)
  • return a string or an object
  • read and write GuiXT variables and long text variables
  • display your own Windows.Forms dialog with form.ShowDialog()
  • call methods of an ActiveX control embedded in the SAP GUI screen with the Control command
  • use SAP GUI scripting with the analogous CallVBAsync command

The .NET class library (dll) can be made available locally or centrally, e.g. in SAP Web Repository or SAP Mime Repository

Prerequisites:

  • Component "GuiXT Controls" is active
     
  • The folder  ".NET class libraries" (guixt.ini parameter VBDirectory) is specified in GuiXT profile. All options that are available for the script directories can be used, e.g.

    VBDirectory  SAPWR:ZGUIXTVB
     
  • The interface library guinet.dll (part of the GuiXT Setup) and your own class library are contained in the ".NET class libraries" folder
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  funcname 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  funcname 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 SAP Web Repository or SAP Mime Repository into the local GuiXT cache folder.

If you use the SAP Web Repository or 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.

Besides string formats, object references are possible both for parameters and for the return values; see next paragraph.

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().
 

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.

Exmple:

In the VB.NET-Funktion "newcustomer" we create a new object of class "customer" and return the object reference to GuiXT:

Public Function newcustomer() As customer

  Dim c As New customer

  c.name = "abc GmbH"

  Return c

End Function

In a second VB function we expect an object of class "customer" as parameter and we return the name attribute:

Public Function customername(ByVal cust As customer) As String

  Return cust.name

End Function

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:

CallVB c1 = mylib.class1.newcustomer

...

CallVB name = mylib.class1.customername "&V[c1]"


Now the variable V[name] contains the string "abc GmbH".

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:

// GuiXT Script

// set some demo values
Set V[region.1] "Americas"
Set V[sales.1] "2584"
 
Set V[region.2] "Europe"
Set V[sales.2] "1228"

Set V[region.3] "Asia"
Set V[sales.3] "1628"

// call excel
CallVB excel = mylib.office.StartExcel 3

 

In VB.NET we add a reference to "Microsoft.Office.Interop.Excel"  in order to be able to use static typing:

' VB
Function StartExcel(ByVal rows As String) As Excel.Application

  Dim oXL As Excel.Application
  Dim oWB As Excel.Workbook
  Dim oSheet As Excel.Worksheet

  oXL = CreateObject("Excel.Application")
  oXL.Visible =
True

  oWB = oXL.Workbooks.Add()
  oSheet = oWB.ActiveSheet
  oSheet.Columns(1).ColumnWidth = 30
  oSheet.Columns(2).ColumnWidth = 20

  For k = 1 To CInt(rows)
    oSheet.Cells(k, 1).Value = guixt.GetVariable(
"region." & k)
    oSheet.Cells(k, 2).Value = guixt.GetVariable(
"sales." & k)
    
Next
   
   
Return oXL

End Function

Components GuiXT + Controls