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!

Easy (?) newbe question 1

Status
Not open for further replies.

shar

Technical User
Apr 2, 2000
54
0
0
IR
I am new to this, so please bear with me.

How do you step through a vbs script? I know you save the commands in a text file with vbs extension and double click on it to run it. I have done that, but something in my script does not work. How can I step through the code one line at a time to find out which part of it is not correct?

Thanks.
Shar
 
you will need Windows Script Debugger (on windows CD or you can download it). I use an editor called PrimalScript and you can debug from there.

Or if you want explain your problem and we we can assist you .
 
You can always display the values of certain variables when you run it using echo or msgbox commands.
 
Thank you for your responses. I tried the Windows Script debugger, but it seems that it is for html and java codes. Well, here is the code I am having trouble with. It is a VB script called from MS Access to update the front end of an Access application. I got it from FAQ of Tek-Tips' Access Modules forum.

The Access function checks version numbers between a master copy and the users local copy, if different the following line of code is run:

fHandleFile "D:\db\VXP\UpdateFrontEnd.vbs", WIN_NORMAL

UpdateFrontEnd.vbs:
' * * * * Start * * * * *
Dim strLocalPath
Dim strNetPath
Dim FSO

strLocalPath = Left(WScript.scriptfullname, Len(WScript.scriptfullname) - Len(WScript.scriptname)) & "Projs.mdb"

strNetPath = "D:\db\VXP\Projs.mdb"

Set FSO = CreateObject("Scripting.FileSystemObject")

Do While FSO.FileExists(Left(strLocalPath, Len(strLocalPath) - 3) & "ldb") = True
'As long as an ldb file exists, someone is in the database, so just do nothing until it goes.
Loop

Set WshShell = WScript.CreateObject("WScript.Shell")

FSO.CopyFile strNetPath, strLocalPath, True
WshShell.Run strLocalPath
' * * * * End * * * * *

fHandleFile Function:
' * * * * Start * * * * *
Private Function fHandleFile(stFile As String, lShowHow As Long)
Dim lRet As Long, varTaskID As Variant
Dim stRet As String
'First try ShellExecute
lRet = apiShellExecute(hWndAccessApp, vbNullString, _
stFile, vbNullString, vbNullString, lShowHow)

If lRet > ERROR_SUCCESS Then
stRet = vbNullString
lRet = -1
Else
Select Case lRet
Case ERROR_NO_ASSOC:
'Try the OpenWith dialog
varTaskID = Shell("rundll32.exe shell32.dll,OpenAs_RunDLL " _
& stFile, WIN_NORMAL)
lRet = (varTaskID <> 0)
Case ERROR_OUT_OF_MEM:
stRet = &quot;Error: Out of Memory/Resources. Couldn't Execute!&quot;
Case ERROR_FILE_NOT_FOUND:
stRet = &quot;Error: File not found.Couldn't Execute!&quot;
Case ERROR_PATH_NOT_FOUND:
stRet = &quot;Error: Path not found. Couldn't Execute!&quot;
Case ERROR_BAD_FORMAT:
stRet = &quot;Error:Bad File Format. Couldn't Execute!&quot;
Case Else:

End Select
End If
fHandleFile = lRet & _
IIf(stRet = &quot;&quot;, vbNullString, &quot;, &quot; & stRet)

End Function
' * * * * End * * * * *

Here are the constants declaration used in the above function:
Private Const ERROR_SUCCESS = 32&
Private Const ERROR_NO_ASSOC = 31&
Private Const ERROR_OUT_OF_MEM = 0&
Private Const ERROR_FILE_NOT_FOUND = 2&
Private Const ERROR_PATH_NOT_FOUND = 3&
Private Const ERROR_BAD_FORMAT = 11&

Questions/issues:

1- When the code is run through Access of by double clicking the UpdateFrontEnd.vbs, the update does not take place. (?)

2- How can I use the debugger to step through the UpdateFrontEnd.vbs code to find out what is happening and where is it not working. When I open it through MS Script Debugger, all choices under &quot;Debug&quot; menu are greyed out.

3- Can you point me to a site where the apiShellExecute function is explained a bit.

Thanks a lot.
Shar
 
Hi,
Thanks for looking at my FAQ, lets see if we can make it work!!
The ShellExecute api call is from basically it lets you run a file with the default application set up for it. In the case of .vbs files that's wscript.exe or cscript.exe.

To start with I would check the the fHandleFile is working ok by calling fHandleFile(&quot;C:\PathTo\SomeWordFile.doc&quot;,WIN_NORMAL) and seeing if the word file opens.
Howver, looking at your file I think I see the problem. The file is designed to be run from the same folder as the local version of the database, and contains the path to the remote version of the database so
strNetPath = &quot;D:\db\VXP\Projs.mdb&quot; is the path to the remote version of the latest version of the file, but you are calling the file &quot;D:\db\VXP\UpdateFrontEnd.vbs&quot; so the vbscript is copying the file from
&quot;D:\db\VXP\Projs.mdb&quot; (which is generated from strLocalPath = Left(WScript.scriptfullname, Len(WScript.scriptfullname) - Len(WScript.scriptname)) & &quot;Projs.mdb&quot;

)
and copying it to
&quot;D:\db\VXP\Projs.mdb&quot; (from strNetPath)

To make it work, copy the UpdateFrontEnd.vbs into the same directory as the local version of the database and set strNetPath to the remote version of the front end.

hth

Ben

----------------------------------------------
Ben O'Hara &quot;Where are all the stupid people from...
...And how'd they get so dumb?&quot;
rockband.gif
NoFX-The Decline
----------------------------------------------
 
Thanks for the response Ben. After a few hours of working on it, I did find out that what you mentioned was the problem, i.e. trying to copy the file onto itself. I appreciate you taking the time to look into it and pointing out the problem. Here is a star for you.
Thanks.
shar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top