Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 173
  • Last Modified:

VB app not closing properly

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
kbakst
Asked:
kbakst
  • 7
  • 4
  • 2
  • +4
1 Solution
 
kamallCommented:
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
 
kbakstAuthor Commented:
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
 
yowkeeCommented:
kbakst,

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

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
alamoCommented:
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
 
DalinCommented:
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
 
MikeP090797Commented:
Try using the ExitProcess API to end the process, it always workds for me:
Declare Sub ExitProcess Lib "kernel32" (ByVal uExitCode As Long)
0
 
twardCommented:
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
 
kbakstAuthor Commented:
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
 
MikeP090797Commented:
I used it this way:
first Unload frm
and then call ExitProcess 0
0
 
kbakstAuthor Commented:
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
 
kamallCommented:
kbakst,
Is it possible to post your code here?
0
 
kbakstAuthor Commented:
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
 
kbakstAuthor Commented:
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
 
kamallCommented:
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
 
kbakstAuthor Commented:
Final question then:  how do I tell if the sound has finished playing?
0
 
kbakstAuthor Commented:
Got it.  Working now - thanks everyone.
0
 
kamallCommented:
Thanks kbakst, and you are welcome.
For any difficulties, please feel free to comment me.
Best regards.
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 7
  • 4
  • 2
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now