What happen when you exit sub in vb6

What happen when you exit a sub routine in vb6 where does the program goes after you exit sub when there is no more task to run.
1030071002Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

advfinanceCommented:
As VB6 is an event-driven environment, your program will return to an idle state until an event is triggered, such as a button being clicked, a timer fires, etc.
0
Guy Hengel [angelIII / a3]Billing EngineerCommented:
"exit sub" will do the same as when the code would have reached the "end sub"

if the "sub" is the event handler for example of a button_click/menu_click etc, the program will go back to the "idle waiting".
if its the "sub main" startup, it will basically end the application unless at least 1 form is loaded (which will keep the application running also).
0
Brook BraswellApplication Development ManagerCommented:
The subroutine will return to where it was called

private sub Main
   msgbox "Here I am"
   MySub
   msgbox "I am Done"
End Sub

public sub MySub
   msgbox "I am here now"
End Sub

you would get three message boxes
Here I am
I am Here now
I am Done

then program would end.


if you had a user interface then the app waits for an event like button click
if you do not have a user interface and the app has run the last sub the the app should end.

0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

shadow77Commented:
If you want your program to terminate, you can do
        Unload
for every form that is open, especially your main form.

Or you could do
    PostMessage MainForm.hwnd, WM_SYSCOMMAND, SC_CLOSE, 0

For the latter, put these lines at the top of the file in which you use PostMessage
    Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Public Const WM_SYSCOMMAND = &H112
    Public Const SC_CLOSE = &HF060

0
1030071002Author Commented:
if you want your program to wait what would you do :- timer or sleep and what is the difference and which is better
0
shadow77Commented:
Since your program is event driven (assuming it's a form-based program), waiting happens naturally when you exit from your event handlers (such as Form_MouseUp).  Just let each event handler run until completion and your program will then wait for the next event.

If you have some other kind of organization (eg, you run everything from your Form_Load event or you have a button handler that never exits), you can use a function like the one in the box, or you can use Sleep.

Use a timer control if you want to perform some task periodically without having to worry about when to run it in other parts of your program.
    'Yield to other processes for tSecs seconds
Public Sub YieldFor(tSecs As Long)
    Dim t0 As Long
    t0 = Timer   ' Set start time
    DoEvents     ' Yield at least once
    Do While Timer <= t0 + tSecs
        DoEvents   ' Yield to other processes
    Loop
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.