none
Wie kann ich ein SAP Anbindung in Microsoft Visual Basic 2008 Express Edition erreichen? RRS feed

  • Frage

  • Hallo,

    ich habe eine kleine VBS-script für den SAP-Zugriff erstellt. Mit Doppelklick auf diese Datei

    läuft das VBS-script richt ab.

    Nun versuche ich in Microsoft Visual Basic 2008 Express Edition dieses script bearbeiten und als EXE-File exportieren.

    Weis jemand wie das geht?

    Danke D_sap

    Mittwoch, 28. April 2010 08:09

Alle Antworten

  • Hallo,

    ein VBScript kannst Du nicht ohne weiteres 1:1 in VB Express bearbeiten und als EXE Datei kompilieren. Du kannst bspw. eine neue Konsolen Anwendung erstellen und fügst den Code des VBScript in die Main Methode von Module1 an. Wenn Dein VBS in mehrere Prozeduren/Funktionen aufgeteilt ist, musst Du diese natürlich entsprechend als Methoden außerhalb von Main implementieren. Das nur als ganz grober Ansatz, ohne Deinen Code zu kennen.

    Welchen Vorteil versprichst Du Dir davon, ein offensichtlich funktionierendes Skript, in ein Executable zu überführen?


    Thorsten Dörfler
    Microsoft MVP Visual Basic
    Mittwoch, 28. April 2010 17:21
  • Hallo Thosten,

    danke für die Info, ich werde es testen.

    Ich will eine Umsetzung in eine .EXE Datein einsetzen, weil in dem skript Infomationen enthalten sind

    die ein anderer Anwender nicht sehen soll.

    Gruß D_sap

    Donnerstag, 29. April 2010 07:34
  • Hallo Thorsten,

     

    ich habe das VBS eingebaucht bekomme eine menge Fehler, weile variable nicht bekannt sind.

     

    Dim MyPassword
    MyPassword = InputBox("Enter your password:","Zreport")
    If Not IsObject(application) Then
       Set SapGuiAuto  = GetObject("SAPGUI")
       Set application = SapGuiAuto.GetScriptingEngine
    End If
    If Not IsObject(connection) Then
       set connection = application.OpenConnection("unser sap system")
    End If
    If Not IsObject(session) Then
       Set session    = connection.Children(0)
    End If
    If IsObject(WScript) Then
       WScript.ConnectObject session,     "on"
       WScript.ConnectObject application, "on"
    End If
    session.findById("wnd[0]/usr/txtRSYST-BNAME").text = "mustermann"
    session.findById("wnd[0]/usr/pwdRSYST-BCODE").text = MyPassword
    session.findById("wnd[0]").sendVKey 0
    session.findById("wnd[0]/tbar[0]/okcd").text = "sa38"
    session.findById("wnd[0]").sendVKey 0
    session.findById("wnd[0]/usr/ctxtRS38M-PROGRAMM").text = "Zreport"
    session.findById("wnd[0]/usr/ctxtRS38M-PROGRAMM").caretPosition = 8
    session.findById("wnd[0]").sendVKey 8
    session.findById("wnd[0]/usr/ctxtS_MTART-LOW").text = "ztart"
    session.findById("wnd[0]/usr/ctxtS_MTART-LOW").caretPosition = 4
    session.findById("wnd[0]").sendVKey 8

     

    Gibt es eine Libary die ich einbinden kann oder wie soll ich die Variablen deklarieren?

    Z. B. Fehler: IsObject, application, SapGuiAutosession etc. nicht deklariert.

    Gruß d_sap

    Donnerstag, 29. April 2010 09:16
  • Hallo d_sap,

    Habe den folgenden Code gefunden. Vielleicht hilft er Dir etwas weiter.

    Function GrabOrders()
    
    Dim SapApp As Object
    Dim SapConn As Object
    Dim SapSession As Object
    Dim SapGuiAuto As Object
    Dim wnd As Variant
    
    
    
    
     Set SapGuiAuto = GetObject("SAPGUI")
     Set SapApp = SapGuiAuto.GetScriptingEngine
     Set SapConn = SapApp.Children(0)
     Set SapSession = SapConn.Children(0)
    
    If IsObject(WScript) Then
     WScript.ConnectObject SapSession, "on"
     WScript.ConnectObject SapApp, "on"
    End If
    
    SapSession.findById("wnd[0]").Maximize
    SapSession.findById("wnd[0]/tbar[0]/okcd").Text = "sq00"
    SapSession.findById("wnd[0]").sendVKey 0
    SapSession.findById("wnd[0]").sendVKey 19
    SapSession.findById("wnd[1]").sendVKey 71
    SapSession.findById("wnd[2]/usr/txtRSYSF-STRING").Text = "RWHITE"
    SapSession.findById("wnd[2]/usr/txtRSYSF-STRING").caretPosition = 6
    SapSession.findById("wnd[2]").sendVKey 0
    SapSession.findById("wnd[3]/usr/lbl[0,2]").SetFocus
    SapSession.findById("wnd[3]/usr/lbl[0,2]").caretPosition = 3
    SapSession.findById("wnd[3]").sendVKey 2
    SapSession.findById("wnd[1]").sendVKey 0
    SapSession.findById("wnd[0]/usr/ctxtRS38R-QNUM").Text = "ZORDERFREIGHT"
    SapSession.findById("wnd[0]/usr/ctxtRS38R-QNUM").caretPosition = 13
    SapSession.findById("wnd[0]").sendVKey 17
    SapSession.findById("wnd[1]/usr/ctxtRS38R-VARIANT").Text = "STARTUP"
    SapSession.findById("wnd[1]/usr/ctxtRS38R-VARIANT").caretPosition = 7
    SapSession.findById("wnd[1]").sendVKey 0
    SapSession.findById("wnd[0]").sendVKey 12
    SapSession.findById("wnd[0]").sendVKey 17
    SapSession.findById("wnd[1]/usr/ctxtRS38R-VARIANT").Text = "YESTERDAY"
    SapSession.findById("wnd[1]/usr/ctxtRS38R-VARIANT").caretPosition = 9
    SapSession.findById("wnd[1]").sendVKey 0
    SapSession.findById("wnd[0]").sendVKey 8
    SapSession.findById("wnd[1]/usr/chkRSAQDOWN-COLUMN").Selected = True
    SapSession.findById("wnd[1]").sendVKey 0
    SapSession.findById("wnd[1]").sendVKey 0
    SapSession.findById("wnd[0]").sendVKey 12
    SapSession.findById("wnd[0]").sendVKey 12
    
    
    End Function

     

    Ich sehe folgendes:

    Dim SapApp As Object
    Dim SapConn As Object
    Dim SapSession As Object
    Dim SapGuiAuto As Object


    Grüße,

    Robert

     

    Donnerstag, 29. April 2010 10:28
  • Hallo,

    danke für den Text. Ich habe ihn getestet, bekomme aber im debugger immer ein nullreferenceexception

    bei         If Not IsObject(application) Then

    ...

                 end if.

    Meine Deklarationen sind:

            Dim IsObject As Object = Nothing
            Dim application As Object = Nothing
            Dim SapGuiAuto As Object = Nothing
            Dim connection As Object = Nothing
            Dim session As Object = Nothing
            Dim Wscript As Object = Nothing
            Dim MyPassword

    Danke d_sap

    Donnerstag, 29. April 2010 12:24