That definitely shouldn't happen. Can you zip up your project, including the res file, and attach it to a post please ?
Hi,
Thanks a lot for your usual help. I have attached the project. But could not attach the Resourse file & Add Questions form due to the limitation of (size is too large to be attached : zip file is 868 KB) attachment.
Actually what I need for this project is, I have questions and options to select correct answer. All are in text format. Now, I would like to record each question alongwith its options in an audio file giving a name like..Question1.wav, Question2.wav, Question3.wav, ........Question50.wav (.wav or .mp3 file format).
So, when users start the quiz they can see the question & its options in text and when press button "Play Sound" they can listen to that question & options.
How can I do this? Hope to get usual help from you.
Regarding resource file path I have attched .jpg file.
Regards,
Margaret
Last edited by Margaret; Nov 9th, 2006 at 02:54 AM.
Hi Margaret, no probs. The pic and code was enough You need to change the "Type" of resource to "SOUND". In the resource editor, double-click on the "101" and you'll get an "Edit Properties" dialog. Just change the Type to "SOUND". The play code needs to be changed to suit:
VB Code:
Private Sub cmdPlaySound_Click() 'PlaySound. Resource file. SYNCHRONOUS ONLY.
Dim bytResFile() As Byte
bytResFile = LoadResData(101, "SOUND")
Call PlaySoundResMem(bytResFile(0), App.hInstance, SND_MEMORY Or SND_SYNC)
End Sub
("WAVE" also works)
BTW, this code will cause the app to "freeze" while the sounds are played - which is what I assume you want for a Quiz program ie - stop user interaction until the questions/answers are played. As Arne Elster pointed out above, a minor change can alter this behaviour - the only problem being that the "sound file" stored in "bytResFile()" will remain in memory for the duration of the app. Although it can be erased, there is no easy (one liner) way to do this automatically - although it is possible. A better way is to use code that doesn't involve this overhead - the problem being it will only play sounds after you've made an exe. It won't play in the IDE If you want this alternative, just let me know.
Hi Margaret, no probs. The pic and code was enough You need to change the "Type" of resource to "SOUND". In the resource editor, double-click on the "101" and you'll get an "Edit Properties" dialog. Just change the Type to "SOUND". The play code needs to be changed to suit:
VB Code:
Private Sub cmdPlaySound_Click() 'PlaySound. Resource file. SYNCHRONOUS ONLY.
Dim bytResFile() As Byte
bytResFile = LoadResData(101, "SOUND")
Call PlaySoundResMem(bytResFile(0), App.hInstance, SND_MEMORY Or SND_SYNC)
End Sub
("WAVE" also works)
The audio file name is "Welcome.wav". I put this file in Resource Folder. I am still confused since it doesn't play the sound.
Try the project in this zip file. Very, very rarely, PlaySound fails on some PCs. Let me know if it works OK.
EDIT: Attachment removed. See later post.
Last edited by schoolbusdriver; Nov 13th, 2006 at 03:03 PM.
The audio file name is "Welcome.wav". I put this file in Resource Folder. I am still confused since it doesn't play the sound.
Providing you have Type right = "SOUND" and the ID is a number you may have problems hearing the sound in IDE. Compile the exe and try it again.
schoolbusdriver gave me different code to play wave files and I had to compile before I could hear a sound.
Keith
I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.
Providing you have Type right = "SOUND" and the ID is a number you may have problems hearing the sound in IDE. Compile the exe and try it again.
schoolbusdriver gave me different code to play wave files and I had to compile before I could hear a sound.
Hi,
Still, I am confused. Suppose I have 10 audio files in a folder "Audio Songs" say, Song1, Song2, Song3 ......Song10, and the folder is in the same project folder. How can I listen to a song Song1 when I click on cmdSong1.
Kindly let me know the easiest way to do this, please.
When you add these songs to a resource file I normally use the filename without the extension. Because that is easy to play that sound. But if you are using schoolbusdriver code with PlaySound API you need to change this to a number so write them down.
Call PlaySound(SoundBuffer, App.hInstance, SND_RESOURCE Or SND_ASYNC)
End Sub
Private Sub cmdSong1_Click()
Call PlaySounds(101)
End Sub
Are your sound types "SOUND"?
Last edited by Keithuk; Nov 11th, 2006 at 06:07 PM.
Keith
I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.