Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
stefan_schnell
Active Contributor
0 Kudos
The basically way to use dotNET languages I describe here.

Here is now an alternative to use dotNET library source files direct inside SAP GUI Scripting.

At first a source code of a Visual Basic dotNET library file:
'-Begin-----------------------------------------------------------------

'-Directives----------------------------------------------------------
Option Strict On

'-Imports-------------------------------------------------------------
Imports System
Imports Microsoft.VisualBasic

'-VBCode--------------------------------------------------------------
Namespace VBCode

Public Class VB

Public Shared Function Hello1() As String
Return "Hello World!"
End Function

Public Function Hello2(ByVal Name As String) As String
Return "Hello " & Name & "!"
End Function

Public Sub Hello3(ByVal Name As String)
MsgBox(Name, MsgBoxStyle.OkOnly, "Hello")
End Sub

End Class

End Namespace

'-End-------------------------------------------------------------------

 

You can compile this code via

vbc /target:library /out:MyLib.dll MyLib.vb

to a library an use it inside your VB projects.

 

Also you can use this code direct inside VBScript resp. SAP GUI Scripting:
'-Begin-----------------------------------------------------------------

'-Directives----------------------------------------------------------
Option Explicit
On Error Resume Next

'-Constants-----------------------------------------------------------
Const OUTPUT_BUFFER = 2
Const ForReading = 1
Const FileName = "MyLib.vb"

'-Variables-----------------------------------------------------------
Dim FSO, File, VBCode
Dim PS, PSCode, PSOutput

'-Main----------------------------------------------------------------

'-Read the VBSharp code---------------------------------------------
Set FSO = CreateObject("Scripting.FileSystemObject")
If IsObject(FSO) Then
Set File = FSO.OpenTextFile(FileName, ForReading)
VBCode = File.ReadAll
File.Close
Set FSO = Nothing
Else
MsgBox "Can't create FileSystemObject", vbOkOnly, _
"Important hint"
End If

If VBCode <> "" Then

Set PS = CreateObject("SAPIEN.ActiveXPoSH")
If IsObject(PS) Then

PS.OutputMode = OUTPUT_BUFFER

If PS.Init(vbFalse) = 0 And PS.IsPowerShellInstalled() <> 0 Then

PSCode = "$VBCode = @""" & VBCode & """@;"
PSCode = PSCode & vbCrLf
PSCode = PSCode & "Add-Type -TypeDefinition $VBCode " & _
"-Language VisualBasic"
PSCode = PSCode & vbCrLf
PSCode = PSCode & "$VB = new-Object VBCode.VB"
PSCode = PSCode & vbCrLf

'-Execute the different modules-------------------------------
PSCode = PSCode & "[VBCode.VB]::Hello1()"
PSCode = PSCode & vbCrLf
PSCode = PSCode & "$VB.Hello2(""Stefan"")"
PSCode = PSCode & vbCrLf
PSCode = PSCode & "$VB.Hello3(""Stefan"")"

PS.Execute(PSCode)
MsgBox PS.OutputString(), vbOkOnly, "VB# results"

End If
Set PS = Nothing
Else
MsgBox "Can't create ActiveXPoSH", vbOkOnly, "Important hint"
End If

End If

'-End-------------------------------------------------------------------

 

At first we read the source of the library in the variable VBCode. Now we insert this content in the context of the PowerShell script code inside the variable PSCode. At last we execute the code and it runs perfect.

Now it is very easy to code dotNET language classes and to use this classes multiple, e.g. in your dotNET projects and inside SAP GUI Scripting.

Also you can use this way with GuiXT. GuiXT offers with the commands CallVBS and CallVBSAsync full access to VBScript. With GuiXT you can change the SAP Screens without any modifications in the SAP backend. The combination between GuiXT, SAP GUI Scripting and Sapiens PowerShell bridge to the dotNET functionalities offers new horizons of possiblities on presentation server development.
Labels in this area