Solved

VB app not closing properly

Posted on 1998-07-09
17
160 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
Comment Utility
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
Comment Utility
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
Comment Utility
kbakst,

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

0
 
LVL 6

Expert Comment

by:alamo
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 8

Expert Comment

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

Author Comment

by:kbakst
Comment Utility
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
Comment Utility
kbakst,
Is it possible to post your code here?
0
 

Author Comment

by:kbakst
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Final question then:  how do I tell if the sound has finished playing?
0
 

Author Comment

by:kbakst
Comment Utility
Got it.  Working now - thanks everyone.
0
 
LVL 7

Expert Comment

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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…

763 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now