Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Runtime errors, either way

Status
Not open for further replies.

cold25

Programmer
Feb 11, 2002
41
0
0
US
Hi. I've modified a vb script example from the msdn page to start my own script. When I put it inside my VB6 program and try to run it like this:

Dim WshShell
Dim WScript

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run """C:\Program Files\Hewlett-Packard\Digital Imaging\bin\Hpqdirec.exe"""
WScript.sleep 1000
WshShell.AppActivate "HP Director"
WScript.sleep 100
WshShell.SendKeys "%{s}"
WScript.sleep 500
WshShell.SendKeys "~"
WScript.sleep 500
WshShell.SendKeys "{DOWN 1}"
WScript.sleep 500
WshShell.SendKeys "~"
WScript.sleep 500
WshShell.SendKeys "~"
WScript.sleep 2500

it says: "Object required", referencing my Set WshShell = WScript.CreateObject("WScript.Shell") line. I then changed only the first two lines to:

Dim WshShell
Dim WScript

Set WshShell = CreateObject("WScript.Shell")
Set WScript = CreateObject("WScript.Shell")
WshShell.Run """C:\Program Files\Hewlett-Packard\Digital Imaging\bin\Hpqdirec.exe"""
WScript.sleep 1000
WshShell.AppActivate "HP Director"
WScript.sleep 100
WshShell.SendKeys "%{s}"
WScript.sleep 500
WshShell.SendKeys "~"
WScript.sleep 500
WshShell.SendKeys "{DOWN 1}"
WScript.sleep 500
WshShell.SendKeys "~"
WScript.sleep 500
WshShell.SendKeys "~"
WScript.sleep 2500

It then stops me at the WScript.sleep 1000 line, and says: Object doesn't support this property or method." I'm confused as to why the sleep method works in the example at msdn, but not in my script, once I've placed it into my VB6 program. I've gone to got an appropriate download, and looked for guidance there, as was suggested to me previously, but haven't been able to figure out why the sleep method (and the AppActivate, I suspect, too) isn't working. Any help with this issue would be greatly appreciated. Thanks.
cold25
 
VBScript programs must be saved with a .VBS extension and launched with either cscript (console mode) or wscript (gui mode). They aren't supposed to compile as VB6 programs.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hi. So you're saying that I should write my script in a .vbs file totally outside of my vb6 program, and then set my cmdButton in the vb6 program to launch it, in a fashion similar to the one which you helped me with yesterday?:

WshShell.Run """C:\Program Files\Hewlett-Packard\Digital Imaging\bin\Hpqdirec.exe"""

I did try to execute my first block of code above in a .vbs file after I couldn't get the sleep method to be accepted and work in the vb6 program. Howver, although it doesn't cause any runtime errors, it still seems to execute my sendkey commands too quickly, before the program I'm openining has opened. So I'm wondering, do I need to make it sleep longer, or I'm thinking more likely, are the sleep and AppActivate methods not working correctly in the .vbs file either?

cold25
 
Provided you have the last scripting runtime the WScript.Sleep and WshShell methods work correctly.
The argument of the Sleep method is a number of milliseconds.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
You were right about the sleep method working. It appears to be working better after increasing the value from 1000 to 5000, to test it. Your help has been of great value to me. Hopefully this will flow smoother now that the script is its own external program, and out of vb6. Thanks again!
cold25
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top