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

Need to return a value from a VB program that I shell from another. 1

Status
Not open for further replies.

IAMQSC

Programmer
Jan 15, 2002
3
US
I am using the shell command to execute a VB program from inside a VB program and I need to have the 'shelled' program retun a value to the VB program that called it. Is this possible?

Thanks,
--- Q
 
It is possible - you should try doing a keyword search in this forum as it has definately come up before - I'm not at work so I don't have the code to hand - sorry
 
Thanks, I reworded my search a few times and found an answer.
 
IAMQSC: for future users that find this thread, it may be worth while to point them to your solution (thread).

just a suggestion [wink]

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
File Formats Galore @
 
I posted this solution quite a while ago, and don't which thread it's in, but here it is:

The following sequence can be used to shell out to another program, wait for it to finish execution and get a value, of type Long, back from the called program.
In the calling program, include a reference to the Windows Host Scripting Object
Code:
   Dim RetVal As Long
   Dim WSH As IWshShell
   Dim WaitForTermination as Boolean
   Dim CommandLine as String

   Set WSH = New IWshShell_Class
   CommandLine = &quot;<Your Program Pathname Here>&quot;
   WaitForTermination = True
   RetVal = WSH.Run(CommandLine, vbNormalFocus, WaitForTermination)
   MsgBox &quot;Process returned: &quot; & RetVal
   Set WSH = Nothing
and in the external program, use the ExitProcess API something like the following:
First declare the function
Code:
Private Declare Sub ExitProcess Lib &quot;kernel32&quot; (ByVal ReturnCode As Long)
and in the Main Form's unload event add the following line:
Code:
ExitProcess LongNumberValue


Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top