Solved

VB app not closing properly

Posted on 1998-07-09
17
163 Views
Last Modified: 2010-05-18
OK - this one is killing me.  I have an application that has a form that acts as a main menu.  If I open JUST that form, and then hit my exit button (which just unloads the form) the application ends just fine.  If I have another form load (a special "pretty" message box with just an OK button) and then hit Exit, the form unloads, but the processor time goes up to 100%, and the executable (ETI.EXE) shows up as a running process (in DLLSHOW), but NOT in task manager.

This is causing ALL kinds of problems for me.  I have put Set <YouNameIt> = Nothing on most everything I can think of, to no avail.  I have even run this IN the IDE in VB on the machine in question.  The processor time peaks when I EXIT VB!

Please help - there's 300 points in it for ya.
0
Comment
Question by:kbakst
  • 7
  • 4
  • 2
  • +4
17 Comments
 
LVL 7

Expert Comment

by:kamall
ID: 1465371
Well...., this is a preliminary answer.
If you have a message box showing on the screen, it is not possible to unload the form that showed the message box. Most probably, this is your problem.
If you post the code here, I can diagnose the fault.

Regards
0
 

Author Comment

by:kbakst
ID: 1465372
That is not the problem.  There is nothing open.  Like the original question says, I click the exit button of the main menu form - meaning that a message box could not be open.  I had to use DLLSHOW to see the process running.

Also - the message box is not a generic VB message box - it is a form I created to make it look nicer.
0
 
LVL 4

Expert Comment

by:yowkee
ID: 1465373
kbakst,

  Any custom controls you are using in your forms? And do you use any APIs or doing some heavy processing?

0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

 
LVL 6

Expert Comment

by:alamo
ID: 1465374
If you put an "End" into your form unload event, does it solve the problem? I am not saying this is necessarily the right approach, but it would be interesting to know this.
0
 
LVL 9

Expert Comment

by:Dalin
ID: 1465375
kbakst,
What do you have (code in the [OK] button's click event on your message form? what is in your [exit] button's click event and if any, in the form's unload event?
regards
Dalin
0
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1465376
Try using the ExitProcess API to end the process, it always workds for me:
Declare Sub ExitProcess Lib "kernel32" (ByVal uExitCode As Long)
0
 
LVL 7

Expert Comment

by:tward
ID: 1465377
Make sure in the Unload of the Main form that you Unload any other forms that you had loaded such as your message box form.
0
 

Author Comment

by:kbakst
ID: 1465378
OK - in order:

tward:  All of the forms are already closed.  I have even gone into the VB IDE and checked the forms collection to be sure that only the main menu is open.

yowkee:  I have a custom control (a button called comic.ocx) that I have had some minor problems with in the past.  Anything in particular I should look for?

alamo:  Tried the END - doesn't work.

Dalin:  the message box is closing properly, as evidenced by my not above to tward.  The only code on the unload event of the exit button on the main menu is something that plays a sound - and I've even tried taking that out.

MikeP:  tried that, and it seems to still leave the window open, but in a very weird state - what exitcode should I be using?  Can't seem to locate it in the API documentation I have.

Upped the points to 350 given the difficult nature (and responses!) of this question.

Thanks in advance.
0
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1465379
I used it this way:
first Unload frm
and then call ExitProcess 0
0
 

Author Comment

by:kbakst
ID: 1465380
MikeP:  I added the ExitProcess command to the form_unload event of my main menu.  The processor time still peaks, and the process still shows as active in SHOWDLL, but now the window itself does not get "undrawn" - meaning it is still on the screen, with a button on the Windows taskbar.
0
 
LVL 7

Expert Comment

by:kamall
ID: 1465381
kbakst,
Is it possible to post your code here?
0
 

Author Comment

by:kbakst
ID: 1465382
I could email the main menu code and message box code to whoever is interested.  My address is kelly.bakst@evalflex.com - just ask.
0
 

Author Comment

by:kbakst
ID: 1465383
OK folks - a break in the action.  I have now tracked the problem down to - of all things - the mciSendString API.  The message box is calling that to produce a nifty sound, and THAT is what is hanging the process.  If I take it out, everything works fine.

So:

1.  Are there any known bugs with the mci API?  And fixes?
2.  Is there any downside to using sndPlaySound instead?
0
 
LVL 7

Accepted Solution

by:
kamall earned 350 total points
ID: 1465384
kbakst,
Here's an example that demonstrates how to load a wave file into a byte array and play it via the API.  Create a new project and paste the following code into the Form1 module.  Run the project.

    Private Declare Function sndPlaySound Lib "winmm" Alias "sndPlaySoundA" (lpszSoundName As Any, ByVal
    uFlags As Long) As Long
    Private Const SND_SYNC = &H0
    Private Const SND_ASYNC = &H1
    Private Const SND_NODEFAULT = &H2   ' Don't use default sound
    Private Const SND_MEMORY = &H4      ' lpszSoundName points to a memory file.
    Private Const SND_LOOP = &H8        ' Loop the sound until next sndPlaySound.
    Private Const SND_NOSTOP = &H10     ' Don't stop any currently
    Const SOUND_FILE = "C:\Windows\Media\Robotz Error.wav"

    Dim bSound() As Byte

    Private Sub Form_Load()

    ReDim bSound(FileLen(SOUND_FILE)) As Byte
    Dim i As Long

    Open SOUND_FILE For Binary Access Read As #1
    For i = 0 To FileLen(SOUND_FILE) - 1
    Get #1, , bSound(i)
    Next
    Close 1

    PlaySoundArray bSound(), SND_NODEFAULT Or SND_SYNC

    End Sub
    Sub PlaySoundArray(bSound() As Byte, sndFlags)

    sndPlaySound bSound(0), sndFlags Or SND_MEMORY

    End Sub

Hope that helps.
For any difficulties, please feel free to comment me.
Regards
0
 

Author Comment

by:kbakst
ID: 1465385
Final question then:  how do I tell if the sound has finished playing?
0
 

Author Comment

by:kbakst
ID: 1465386
Got it.  Working now - thanks everyone.
0
 
LVL 7

Expert Comment

by:kamall
ID: 1465387
Thanks kbakst, and you are welcome.
For any difficulties, please feel free to comment me.
Best regards.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

820 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