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

How to make a vb exe to return value

Status
Not open for further replies.

alicemong

Programmer
Mar 20, 2003
17
0
0
HK
Hi all,

I use the following code to make a vb.exe to return a value and I get the value from another application. However, I don't know why I always get 0 from the application2. In fact, application2 should get 1 instead of 0.

Application1:
Private Declare Sub ExitProcess Lib "kernel32" (ByVal uExitCode As Long)

Private Sub Form_Load()
ExitProcess 1
end sub

Application2:
Private Sub Form_Load()
Dim job As String
Dim retVal As Long
Dim hProcess As Long

BinComparsion = False
job = "D:\FTPGateway\Testing\Project1"
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION,
False, Shell(job, 1))

Do

GetExitCodeProcess hProcess, retVal
DoEvents: Sleep 100
Loop While retVal = STILL_ACTIVE

MsgBox retVal
End Sub

Does anyone know how to solve this problem?
Any responses are welcome

Thanks
Alice
 
Hi paulbent,

Do you mean that I should call the ExitProcess in the Form's Terminate event?

Alice
 
Yes, if app1 is to return an exit code, the call to ExitProcess must be the last thing before the app closes. Therefore it should be at the end of the Form_Terminate event, not Form_Load.

Paul Bent
Northwind IT Systems
http;//
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top