Results 1 to 6 of 6

Thread: Exiting a VB program with a return code

  1. #1
    Guest

    Question

    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.

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    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
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    I think you have to modify this Hesaidjoe:
    Code:
      For i = 1 To Forms.Count - 1
        Unload frm
        Set frm = Nothing
      Next i
    into this:
    Code:
      For each frm in Forms
        Unload frm
        Set frm = Nothing
      Next frm
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  4. #4
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892
    Guys, what about the exit code?
    Code:
    ' General Declarations:
    Private Declare Sub ExitProcess Lib "kernel32" (ByVal uExitCode As Long)
    Then, use ExitProcess like you would use exit in C.
    Code:
    Call ExitProcess(-1)
    You should do that after unloading all the forms...
    Code:
    Dim Form As Form
    
    For Each Form In Forms
        Call Unload(Form)
        Set Form = Nothing
    Next
    
    ' ExitProcess here

  5. #5
    Guest

    Not exactly what I needed!

    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.


  6. #6
    Guest

    Thumbs up Thank you all

    Finally Yonatan solved my doubt. Thanks everyone.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width