I am working with VB 6.0 and I need to know how to make a program exit with a determined return code. In C it would be as simple as writing exit(-1) in the Main function, but I can not find the equivalent in VB. Thank you.
Printable View
I am working with VB 6.0 and I need to know how to make a program exit with a determined return code. In C it would be as simple as writing exit(-1) in the Main function, but I can not find the equivalent in VB. Thank you.
Code:'a walk around..need If x..in any place you might
'change x
Option Explicit
Public x As Boolean
Private Sub Command1_Click()
' all your code
'if requirements are met change value x
x = True
If x = True Then Call UnloadAll
End Sub
Public Sub UnloadAll()
'unload all forms
Dim frm As Form
Dim i As Integer
For i = 1 To Forms.Count - 1
Unload frm
Set frm = Nothing
Next i
End Sub
I think you have to modify this Hesaidjoe:
into this:Code:For i = 1 To Forms.Count - 1
Unload frm
Set frm = Nothing
Next i
Code:For each frm in Forms
Unload frm
Set frm = Nothing
Next frm
Guys, what about the exit code? :rolleyes:
Then, use ExitProcess like you would use exit in C.Code:' General Declarations:
Private Declare Sub ExitProcess Lib "kernel32" (ByVal uExitCode As Long)
You should do that after unloading all the forms...Code:Call ExitProcess(-1)
Code:Dim Form As Form
For Each Form In Forms
Call Unload(Form)
Set Form = Nothing
Next
' ExitProcess here
I want to exit the VB program with a value (for example 2) so that another program or the Operative System can get that value when the VB program finishes execution.
My VB program will have a Sub Main () as the initial point.
In C what I want could be done with:
void main()
{
exit(2) //Or whatever value you want to return to the OS
}
Thank you.
Finally Yonatan solved my doubt. Thanks everyone.