How to get back the control

  • Thread starter Thread starter Prasad Vanka
  • Start date Start date
P

Prasad Vanka

Hi,

I have a user form with command buttons cmdPlay and cmdExit.

cmdPlay_Click has the following code:
Private Sub cmdPlay_Click()
sndPlaySound32 "C:Welcom98.wav", 0
End Sub

This wave file plays for 30 seconds.


cmdExit_Click has the following code:
Private Sub cmdExit_Click()
End
End Sub


After clicking cmdPlay, if I am clicking cmdExit then the program is
not ending immediately. It is waiting for the wave file to finish
playing for 30 seconds. Is it possible that when cmdExit is clicked,
within 30 seconds, then the program should end immediately rather than
waiting for the whole 30 seconds.

Thanks & Regards,
Prasad Vanka
 
Prasad Vanka

Not really sure, but did you set the command buttons take focus o
click to false?

HTH


Charle
 
Hi Charles,

I haven't set the command buttons take focus on
click to false.

regards,
Prasad Vanka
 
Hi Prasad,

Firstly, you need to play the sound asynchronously, otherwise no code will
be able to run until the sound is finished playing.

Secondly, if you call sndPlaySound using vbNullString instead of a wav file,
it will terminate any other sound that happens to be playing.

And last but not least, there's a zillion vb'ers who'll tell you that using
End is asking for trouble. Far safer to unload your userform.

See an example below.


Regards,
Vic Eldridge



Private Const SND_ASYNC = &H1
Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" _
(ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

Private Sub cmdPlay_Click()
sndPlaySound "C:\WINNT\Media\Windows Logon Sound.WAV", SND_ASYNC
End Sub

Private Sub cmdExit_Click()
sndPlaySound vbNullString, 0
Unload Me
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top