Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

VB6 and Program End

Posted on 2006-10-27
5
266 Views
Last Modified: 2010-04-30
Hi,

I have developed a VB6 application that has a form as its 'start up' object.

However the program ends I need it to execute two lines of code, how can I ensure these two lines of code are always executed when the program ends....?

Thanks Ian



0
Comment
Question by:ISC
5 Comments
 
LVL 65

Expert Comment

by:Jim Horn
ID: 17819752
Uhh... simply placing the two lines of code before your 'End' command, or before the last form closes, would probably do the job.
0
 
LVL 2

Expert Comment

by:quarkphoton
ID: 17819774
please put your code in the "form_terminate" event
0
 
LVL 13

Expert Comment

by:jmundsack
ID: 17819793
When you close your main form, the following events will fire:

Form_QueryUnload
Form_Unload
Form_Terminate

The QueryUnload event lets you add code that you want to evaluate to make sure you actually want the form to unload, and a facility to cancel the unload if desired.

The Unload event occurs when the unload was not stopped during the QueryUnload event.

The Terminate event fires after the form has been unloaded, when the COM object that underlies the form is being destroyed.

Where you put your "two lines of code" depends on the content of those two lines.  If they have nothing to do with any of the form's properties (or the properties of any controls on the form), and you want these two lines to be the absolute LAST instructions of your program, I would say put them in Form_Terminate.

HTH-Jon
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 250 total points
ID: 17820704
There isn't a Global "Application Ending" event in VB6.  (There is in VB.Net 2005 though...)

If you have multiple forms in your application then obviously you won't know which form is the "last one" will you?

Consequently we don't know which form should have the two lines in its Unload() event...

Here is an approach that may work.

From EVERY single forms unload event we call the AppClosing() sub in a Module.  From there we check the Forms collection count if it is 1 then we are closing the last form:

' --------------
'  Form1
' --------------
Option Explicit

Private Sub Form_Unload(Cancel As Integer)
    AppClosing
End Sub

' --------------
'  Form2
' --------------
Option Explicit

Private Sub Form_Unload(Cancel As Integer)
    AppClosing
End Sub

' --------------
'  Module1
' --------------
Option Explicit

Public Sub AppClosing()
    If Forms.Count = 1 Then
        ' the last form is closing...
       
        Debug.Print "The app is closing..."
    End If
End Sub
0
 
LVL 1

Author Comment

by:ISC
ID: 17832251
Many thanks for all the above comments....

I like the solution provided by 'Idle_Mind' the best....

Thanks Ian
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question