on 03-08-2012 12:35 PM
Dear EXperts,
Newbie here.
I was able to record something (picking progress in TC LT45) and thus generate a VBS file.
Now, running this script is doing what it should do, except for the timing: It runs way too fast and therefore I am searching for adding some command/code to pause.
I found examples like Application.Wait("0:00:1000") but SAP does not like that.
See 'my' code below.
Any answer will be appreciated.
Thanks, Nick
If Not IsObject(application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
Set connection = application.Children(0)
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]").resizeWorkingPane 263,47,false
session.findById("wnd[0]").sendVKey 8
Application.Wait("0:00:1000")
session.findById("wnd[0]").sendVKey 3
session.findById("wnd[0]").sendVKey 8
Application.Wait("0:00:5000")
session.findById("wnd[0]").sendVKey 3
session.findById("wnd[0]").sendVKey 8
Application.Wait("0:00:1000")
session.findById("wnd[0]").sendVKey 3
session.findById("wnd[0]").sendVKey 8
session.findById("wnd[0]").sendVKey 3
session.findById("wnd[0]").sendVKey 8
session.findById("wnd[0]").sendVKey 3
Edited by: N. Lagace on Mar 8, 2012 1:37 PM
Hello N. Lagace,
in vbs-scripts you have to use this::
wscript.sleep milliseconds
e.g.
. . .
wscript.sleep 6000
. . .
The script will wait 60 seconds an then continue the code.
I allways use it.
Look at:
http://technet.microsoft.com/en-us/library/ee156589.asp
Listing 3.13 Setting the Time-out Value of a Script
Greetings,
netkid
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey Scriptman,
I knew you would respond to my post.
The WScript.Sleep 4000 I already had in place, and yes I start the thing from SAP, and you are right it does not work becaus it says Object Required: WScript
how to deal with that object requirement?
So, your advise to use an other method, is that feasible for a newbie? I already was proud to be digging in VB as a strictly functional guy.
Thanks,
Nick
If Not IsObject(application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
Set connection = application.Children(0)
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]").resizeWorkingPane 263,47,false
session.findById("wnd[0]").sendVKey 8
WScript.Sleep 4000
session.findById("wnd[0]").sendVKey 3
session.findById("wnd[0]").sendVKey 8
WScript.Sleep 4000
session.findById("wnd[0]").sendVKey 3
session.findById("wnd[0]").sendVKey 8
WScript.Sleep 4000
session.findById("wnd[0]").sendVKey 3
session.findById("wnd[0]").sendVKey 8
session.findById("wnd[0]").sendVKey 3
session.findById("wnd[0]").sendVKey 8
session.findById("wnd[0]").sendVKey 3
session.findById("wnd[0]").sendVKey 8
session.findById("wnd[0]").sendVKey 3
session.findById("wnd[0]").sendVKey 8
session.findById("wnd[0]").sendVKey 3
session.findById("wnd[0]").sendVKey 8
session.findById("wnd[0]").sendVKey 3
session.findById("wnd[0]").sendVKey 8
session.findById("wnd[0]").sendVKey 3
session.findById("wnd[0]").sendVKey 8
session.findById("wnd[0]").sendVKey 3
session.findById("wnd[0]").sendVKey 8
session.findById("wnd[0]").sendVKey 3
Edited by: N. Lagace on Mar 9, 2012 12:17 PM
Hey Netkid,
Thank you for responding to my post.
The WScript.Sleep 4000 I already had in place, and yes I start the thing from SAP, and you are right it does not work becaus it says Object Required: WScript
how to deal with that object requirement?
Thanks,
Nick
If Not IsObject(application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
Set connection = application.Children(0)
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]").resizeWorkingPane 263,47,false
session.findById("wnd[0]").sendVKey 8
WScript.Sleep 4000
session.findById("wnd[0]").sendVKey 3
session.findById("wnd[0]").sendVKey 8
WScript.Sleep 4000
session.findById("wnd[0]").sendVKey 3
session.findById("wnd[0]").sendVKey 8
WScript.Sleep 4000
session.findById("wnd[0]").sendVKey 3
session.findById("wnd[0]").sendVKey 8
session.findById("wnd[0]").sendVKey 3
session.findById("wnd[0]").sendVKey 8
session.findById("wnd[0]").sendVKey 3
session.findById("wnd[0]").sendVKey 8
session.findById("wnd[0]").sendVKey 3
session.findById("wnd[0]").sendVKey 8
session.findById("wnd[0]").sendVKey 3
session.findById("wnd[0]").sendVKey 8
session.findById("wnd[0]").sendVKey 3
session.findById("wnd[0]").sendVKey 8
session.findById("wnd[0]").sendVKey 3
session.findById("wnd[0]").sendVKey 8
session.findById("wnd[0]").sendVKey 3
session.findById("wnd[0]").sendVKey 8
session.findById("wnd[0]").sendVKey 3
Hello ScriptMan,
thank you for yor note. The same mistake is at the microsoft page . . .
The statement "wscript.sleep xxxx" does work on my computer.
This little vbs-program works when I start it in SAP itself
and i don't kwow why.
If Not IsObject(application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
Set connection = application.Children(0)
End If
Set session = application.ActiveSession
wscript.sleep 3000
session.findById("wnd[0]/tbar[0]/okcd").text = "SP01" 'Spools
wscript.sleep 3000
session.findById("wnd[0]/tbar[0]/btn[0]").press
wscript.sleep 3000
session.findById("wnd[0]/tbar[1]/btn[8]").press
wscript.sleep 3000
session.findById("wnd[0]/usr/chk[1,3]").selected = true
wscript.sleep 3000
session.findById("wnd[0]/usr/chk[1,3]").setFocus
Set SapGuiAuto = Nothing
Set application = Nothing
Set connection = Nothing
Set session = Nothing
I work with SAP-Frontend für Windows (720 Final Release) and
Microsoft Windows XP 5.1 (2600) Service Pack 3.
Maybe the reason is: there is C:WINDOWSsystem32VBScript.dll (Version 5.7.6002.22589) loaded.
I don't know.
Regards,
netkid
Edited by: netkid on Mar 9, 2012 1:04 PM
Scriptman,
Actually, I just noticed that my code below does perform the first step, (simulate F8), and only then begins to ask about the Object Required: WScript.
That gives me the idea that at least partially the script is running successfully, but needs something to do the second step (simulate F3)
Thanks, Nick
*********************************************************
If Not IsObject(application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
Set connection = application.Children(0)
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]").resizeWorkingPane 263,47,false
session.findById("wnd[0]").sendVKey 8
WScript.Sleep 4000
session.findById("wnd[0]").sendVKey 3
session.findById("wnd[0]").sendVKey 8
WScript.Sleep 4000
session.findById("wnd[0]").sendVKey 3
session.findById("wnd[0]").sendVKey 8
WScript.Sleep 4000
Hi Nick,
If you still should not have any other solution to your problem, you can try the following suggestion:
set wshell = createObject("WScript.Shell")
If Not IsObject(application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
End If
. . .
session.findById("wnd[0]").sendVKey 8
wshell.run "c:\tmp\sleep_4000.vbs",1,true
session.findById("wnd[0]").sendVKey 3
. . .
The file c:\tmp\sleep_4000.vbs contains the following command:
wscript.sleep 4000
Regards,
ScriptMan
Hi Nick,
I deal with that object requirement as follows.
Simply change your first 15 lines in your vbs-code
If Not IsObject(application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
Set connection = application.Children(0)
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]").maximize
with these 9 new lines of code
If Not IsObject(application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
Set connection = application.Children(0)
End If
Set session = application.ActiveSession
session.findById("wnd[0]").maximize
and then write this line down when it's needed in your vbs code:
wscript.sleep 3000 'waiting for 3000 milliseconds
In every of mine vbs code it still works.
Best regards, netkid
From a programming standpoint using sleep states and wait states is not optimal, it makes the script unreliable and take longer to run than it strictly needs to.
I will usually reference fields directly by ID and then write directly to them. IE:
session.findById("wnd[1]/usr/tabsTAB_STRIP/tabpSIVA/ssubSCREEN_HEADER:SAPLALDB:3010/tblSAPLALDBSINGLE/ctxtRSCSEL_255-SLOW_I[1,0]").text = "CC*"
or a simpler reference:
session.findById("wnd[0]/usr/txtMAX_SEL").text = "1000000 "
wnd is the window, then there is a simple hierarchy, so wnd(window number]/[part of window]/[field name]).[text] = [in quotes, the text that should go into the field, or a variable/parameter (no quotes for those)]
You can use the script recording feature to find out what the individual fields references are, or you can use GuiXT, navigate to a field, and note the field name in the GuiXT info box.
Using direct references like this, the system will automatically wait until a field entry is completed before moving to the next one.
I feel this is a more elegant solution than programing wait periods into the script.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.