App won't Close in Development environment

I have an application that (sometimes) will not close down via the Control Box in the top-right corner. All .exes compiled from the same source function fine.

Any ideas what is wrong....

Post comments if you need more info. I have no idea what may be of relevance to help you answer this question. I will say, though, that all forms are set to Nothing....
LVL 3
TheRedGuyAsked:
Who is Participating?
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.

Erick37Commented:
Make sure all forms are unloaded and that you do not reference any form after it is unloaded.  Also avoid the use of the END statement, that will terminate the program without unloading.  Sample unloading code:

'~~~~~~~~~Main Form Code~~~~~~~~~~~~~~~~~~~~~~~~~
Private Sub Form_Unload(Cancel As Integer)
    Call UnloadAllForms(Me.Name)
End Sub
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


'~~~~~~~~~~~~~~~~~~~~Module Code~~~~~~~~~~~~~~~~~
Public Sub UnloadAllForms(sFormName As String)
    Dim Form As Form
   
    For Each Form In Forms
        If Form.Name <> sFormName Then
            Unload Form
            Set Form = Nothing
        End If
    Next Form
End Sub
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0
niniCommented:
Do you mean by "will not close down" that the X clicks and pushes down but then  there is no termination of the program?
0
TheRedGuyAuthor Commented:
Correct. The 'X' pushes down but does nothing else. I have placed breakpoints in the QueryUnload event and the Unload event but neither piece of code is called...
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

karlovaCommented:
Try placing a message box in the form events
Paint
Deactivate
QueryUnload
Unload
and Terminate
to find where the form may be reloading and check your code for implicit references to the form or another form not loaded but which may have a reference to the the form your trying to close in the load event. The Paint and Deactivate events may behave differently outside the IDE
0
niniCommented:
It could be easily as simple as an incorrect property.
Go down your property list for the form and check if there ae any "dont terminate" style properties set to true (if you catch my meaning)
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
wyllikerCommented:

<SNIP> ....

Correct. The 'X' pushes down but does nothing else. I have placed breakpoints in the QueryUnload event and the Unload event but neither piece of code is called...

..... <SNIP>

Please note:  everywhere I mention the QueryUnload event handler below, the same applies for the Unload event handler.


Place a break point in all of your Query_Unload event handlers for every form.  ALL forms' Query_Unload handler will be called UNLESS one of them has returned CANCEL.  This has to be what is happening if the Query_Unload where you had placed a breakpoint was not called - because VB has to call AT LEAST one of them.

To emphasize what had been said above ANY reference to any form or a control on a form will cause that form to be loaded by VB even if you have never shown the form.

As annoying as this may be, you can place a message box call in each Form_Load handler and each Form_Terminate handler that says something like Form Load [formname] and Form Terminate [formname] respectively.

The Terminate event is only received after Query_Unload and Unload events returned with Cancel = False!


If you should see a message box pop up that says load after you had seen a message box for the same form that said Terminate than you have identified which form has been reloaded and you can go through your Query_Unload handlers until you find the one that has a reference to that form.




0
wyllikerCommented:
After re-reading your question I would also like to add something else

From your question ....

I have an application that (sometimes) will not close down via the Control Box in the top-right corner. All .exes compiled from the same source function fine.

.....

The key word I see in this is "sometimes".  Make sure that you haven't tried to build any logic that assumes the order in which each form will be unloaded.  The only way to control the order in which forms are unloaded is to explicitly call the Unload [formname] statement for each form.





0
TheRedGuyAuthor Commented:
OK, everyone, thanks for all the comments. I don't think anything has been said, however, that I haven't thought of or that isn't already incorporated into the app. It used to work fine and I've made no significant changes so I can't understand why it's now misbehaving!

What I really don't get is why the QueryUnload event isn't called when I click the 'X'. I would have thought that would be the first bit of code that would run in response to the click.

Or am I wrong (or not getting something
that one of you has said?
0
TheRedGuyAuthor Commented:
OK, everyone, thanks for all the comments. I don't think anything has been said, however, that I haven't thought of or that isn't already incorporated into the app. It used to work fine and I've made no significant changes so I can't understand why it's now misbehaving!

What I really don't get is why the QueryUnload event isn't called when I click the 'X'. I would have thought that would be the first bit of code that would run in response to the click.

Or am I wrong (or not getting something
that one of you has said?
0
TheRedGuyAuthor Commented:
OK, everyone, thanks for all the comments. I don't think anything has been said, however, that I haven't thought of or that isn't already incorporated into the app. It used to work fine and I've made no significant changes so I can't understand why it's now misbehaving!

What I really don't get is why the QueryUnload event isn't called when I click the 'X'. I would have thought that would be the first bit of code that would run in response to the click.

Or am I wrong (or not getting something
that one of you has said?
0
Erick37Commented:
Can you close the program from the stytem menu's Close item?
0
AnswerTheManCommented:
perhaps you try to Click the X while some loop is proccesing itself...
that's why it is SOMETIMES.

try to add a DoEvents Statment in all your loops(if exists) and check it again.

ATM
0
TheRedGuyAuthor Commented:
Erick37 - Yes, no problem there.

AnswerTheMan, Nothing doing (literally!)

All,

Incidentally, in the form's Load event, I set it's Height and Width properties and Maximize it. Reason being that I want the Restore button to set the form to a size such that some of the controls are still visible; in Maximised state all supported functionality is available but app can be 'Restored' to a size where partial functionality is available.

Interestingly, if I change any of the properties that relate to size and position prior to running the app I don't get the problem. I'm confused!

TheRedGuy
0
AnswerTheManCommented:
i guess it's time for some code sample.
since this is weired behaviour, it is almost sure you have done something wrong in your code.
Is this the Only Form in the project ?
are you sure there is no situation that as a result of this resizing there are 2 forms exactly covering each other....?
is there any MDI form there ?

a lot of questions. few details.
0
TheRedGuyAuthor Commented:
OK folks, found the problem. I recently changed the form's .BorderStyle property to 'none'. According to the Help file, you can't have set the .ControlBox property set to 'true'.

Sorry if I wasted anybody's time. It didn't occur to me that this may be the case (and, frankly, I can't see why it has to be).

I guess Nino's suggestion to check the form's properties was the one that led to the solution.

I'll post points if he posts as answer.

Thanks to all

0
Erick37Commented:
That's odd.  In VB5, if you have a borderless form, there is no caption bar or system menu or min/max/close buttons.
0
TheRedGuyAuthor Commented:
That's what I thought the Help File was suggesting but, sure enough, the app would fire and up and run, showing no border and the min/max/close buttons.....
0
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.