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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Return error code from .exe 3

Status
Not open for further replies.

RobSchultz

Programmer
Jun 1, 2000
444
US
I've been trying without success to return an error code (actually more of a result code) from a VB6 .exe file to a WSH script (the exe is called with WScript.Shell.Run). I've tried err.raise and the SetLastError api. There is one form and one module with Sub Main() starting up in the module. I'm sure it is very simple but I just can't figure it out.

Any help will be greatly appreciated,
Rob
robschultz@yahoo.com
-Focus on the solution to the problem, not the obstacles in the way.-
 
Rob,
Do you have an "On error" clause?
On Error GoTo ErrorLabel
<vb statements>
<code that causes or raises error>
<more vb statements>

ErrorLabel
<routines to process WSH>
Resume Next
or
exit sub
or
whatever

Was that what you were asking??

Paul
 
Not quite. I have a WSH script that executes a VB6 program. I want to return an exit code from the VB6 program back to the WSH script (
Code:
retVal = oWSH.Run(&quot;myprogram.exe&quot;,1,True)
) where retVal would receive the return code. Within the VB6 prog I have a single form and a single module with the startup being Sub Main() within the module.

How do I return back a value from the VB6 program to its calling script.

Thanks, Rob
robschultz@yahoo.com
-Focus on the solution to the problem, not the obstacles in the way.-
 
WooHoo! Here is the answer (from VBCity.com forums - member jspano)

Code:
Private Declare Sub ExitProcess Lib &quot;kernel32&quot; (ByVal uExitCode As Long)

ExitProcess somenumber

I knew it would be simple. I guess I need an API guide. [smarty]

Thanks, Rob
robschultz@yahoo.com
-Focus on the solution to the problem, not the obstacles in the way.-
 
Rob - Make absolutly sure you've closed all your file and database connections before calling that function. It doesn't clean up after itself, and you will have memory/resource leaks on the Win9x platforms.

Chip H.
 
Thanks for the site Tranman. I'm sure it will come in handy. I had been using but it has become a bit outdated (they've stopped updating it).

Thanks Chip. Yup, It is placed at the very end of the routine and this particular program doesn't use any external objects or databases. I'll keep your advise in mind when I next use the ExitProcess API Rob
robschultz@yahoo.com
-Focus on the solution to the problem, not the obstacles in the way.-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top