Imports System.ReflectionModule Module1 Public WithEvents application As SAPbouiCOM.Application Public company As SAPbobsCOM.Company Public Function SetConnectionContext() As Integer Try Dim bnnStrCookie As String Dim bnnStrConnectionContext As String company = New SAPbobsCOM.Company bnnStrCookie = company.GetContextCookie bnnStrConnectionContext = application.Company.GetConnectionContext(bnnStrCookie) If company.Connected = True Then company.Disconnect() End If SetConnectionContext = company.SetSboLoginContext(bnnStrConnectionContext) Catch Ex As Exception application.MessageBox(Ex.Message) Finally End Try End Function Public Sub SetApplication() Dim bonGuiSboGuiApi As SAPbouiCOM.SboGuiApi Dim bnnStrConnectionString As String bonGuiSboGuiApi = New SAPbouiCOM.SboGuiApi Try bnnStrConnectionString = Environment.GetCommandLineArgs.GetValue(1) bonGuiSboGuiApi.Connect(bnnStrConnectionString) application = bonGuiSboGuiApi.GetApplication() Catch Ex As IndexOutOfRangeException bnnStrConnectionString = "0030002C0030002C00530041005000420044005F00440061007400650076002C0050004C006F006D0056004900490056" bonGuiSboGuiApi.Connect(bnnStrConnectionString) application = bonGuiSboGuiApi.GetApplication() Catch Ex As Exception application.MessageBox(Ex.Message) Finally End Try End Sub Private Sub Class_Init() SetApplication() If Not SetConnectionContext() = 0 Then application.MessageBox("Failed setting a connection to DI API") End End If If Not ConnectToCompany() = 0 Then application.MessageBox("Failed connecting to the company's Data Base") End End If application.StatusBar.SetText("Connected...", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success) End Sub Public Function ConnectToCompany() As Integer Try If company.Connected = True Then company.Disconnect() End If ConnectToCompany = company.Connect Catch Ex As Exception application.MessageBox(Ex.Message) Finally End Try End Function Sub Main() Try Class_Init() Catch Ex As Exception application.MessageBox(Ex.Message) Finally End Try End SubEnd Module