VB6 app start and end

Working on some code related to VB6 and moving it
My recollection of VB6 is horrible as its been more than a decade
I know Sub Main is roughly the equivalent of the App.Open event
In vb6 whats the equivalent of the App.Close event ?

Unload? QueryUnload? Something like that? Memory is rusty and I haven’t had VB6 installed in a decade.

The command End is what is commonly used to exit a program. It closes any open files and clears variables, and closes the program. It does not free up resources from open windows, so you may want to close these first.

If it’s a Windows Forms app, I believe you just need to use the Form_Unload event of the main form. Console apps - it’s been way too long.

There were two different ways to start an application. 1- Name a default form. Then the Form.Open event was the start event. 2- define a sub main in a module and use that instead.

If I recall correctly, the application could be closed in two ways also. Close all forms (through the Unload command in code or using the control box) or with an End command in code

I think what Norm is asking is not HOW to close an app, but what Event in VB6 is equivalent to CANCELCLOSE and/or CLOSE

Form_Unload is roughly the same as Window.Close
QueryUnlod and Terminate are also form related
I’m looking for one at the App level but not having any luck
Just trying to be thorough in something I’m working on but I can’t see there is an “App.Unload” event or method that gets called when a VB6 app quits

I’m by no means a VB expert, but I happen to have VB6 (SP6) installed in a VM. The Form Unload event signature looks like the following:

Private Sub Form_Unload(Cancel As Integer) ' Cancel is 0 by default End Sub
And if I put the following in a button on a Form, it appears the quit the application:

Unload Me

I hope that helps.

There is no “App.Unload” event that happens when you call “Exit” is there ?


I don’t think there is one. If you’re maintaining a VB6 code base and need one there are various work arounds to make sure a function gets called at program termination. (Though I don’t think any of them can deal with a call to End.) If you’re porting the code to Xojo or .NET and you’re trying to find out if they had code which executed at program termination I would say look at their Form_Unload events. There may be form which will naturally be the last to close and which contains relevant code.

Exit or Quit do not appear to be stand-alone commands in VB6, or I’m doing something wrong(?)

There is a Form_Terminate event that occurs after Form_Unload is called though.

But the End command appears to quit the app completely, without invoking Form_Unload or Form_Terminate.

Norman, you probably know better how to find what you’re looking for, if you want to try a screen-share session or something? PM me if you want.

I don’t recall any event upon program terminate.

I dont either which is why I asked
Really just wanted to make sure I was not overlooking something in the work I’m doing

Ignoring direct exits, like End
If in the project prefs you select either to start sub main, rather than a form, then you open form(s) from within main - don’t you then get control back to main after the form(s) are closed … is that not effectively your app.close point.

If memory serves, Sub Main is used if the app doesnt use a specific form as the main loop

You can set the project to work with a default form
If you do, the ‘end’ of the application happens when that form unloads

If you choose to have the project centred around Sub Main, it wouldnt last long (eg it would work like a console app, performing all the code in Sub Main then exiting)

Some Sub Main methods launch a window, like this:

[quote]Sub Main()
'instantiate globals

Load frmMain ' Open your form

'frmMain has closed, so do what you need to do at the application end here

End Sub[/quote]

@Jeff Tullin - right - I was just wondering if there was the equivalent of the Xojo App.Close event handler but there doesnt seem to be
And thats ok


“Tutorial: How to End a Visual Basic Application properly”

There is a tutorial that I had printed out years ago By Patrik Malmquist and Dave Applegate. I had set my old VB6 programs to terminate as they described. I’m looking at the printout now, it is about 3.5 printed pages.

I cannot vouch for how proper it was, but that is what my old VB6 apps used. The last page sums it up.