Solved

PLAY (MUSIC) command.

Posted on 1998-07-14
7
452 Views
Last Modified: 2008-02-26
In QBasic there is the command PLAY to play musical tunes e.g.

PLAY "CDEFGAB"  - How do I replicate this in VB4?

Thanks.
0
Comment
Question by:deighton
  • 4
  • 2
7 Comments
 
LVL 2

Expert Comment

by:seahpc
Comment Utility
Const SND_SYNC = &H0
Const SND_ASYNC = &H1
Const SND_NODEFAULT = &H2
Const SND_LOOP = &H8
Const SND_NOSTOP = &H10

Function PlaySound(PathFileName as string) as boolean
Dim RetVal as Long
Dim iFlags as Integer

   iFlags = SND_ASYNC Or SND_NODEFAULT
   RetVal = sndPlaySound(PathFileName, iFlags)
   If RetVal Then PlaySound = True

End Function

You must add the following declare to your project in a module (All on one line):

Declare Function sndPlaySound Lib "WINMM.DLL" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

Call this function with a statement like:

PlaySound "D:\Sounds\Fire.Wav"

If you have a need, it is a function that will return true if the sound was played successfully.  Check out the other flags, you might like some of the other things you can do with this API function.
0
 
LVL 18

Author Comment

by:deighton
Comment Utility
I've used your code but there is no sound and
  RetVal = sndPlaySound(PathFileName, iFlags)

RetVal = 0 ??  

The path name is definitel correct and I've used windows wav files such as bell.wav


0
 
LVL 18

Author Comment

by:deighton
Comment Utility
I forgot to mention I've not got multimedia I'm using the PC speaker - I've managed to play windows default sounds using the MessageBeep API so far.  Can I play WAV files thru the speaker?
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 6

Accepted Solution

by:
clifABB earned 50 total points
Comment Utility
I'm sorry to inform you, but there is no equivilant of QB's PLAY command in VB.  There used to be an API call for Windows 3.x that allowed for frequency and duration changes but it is no longer supported (and in fact doesn't work).

In answer to your second question, there is a 16-bit driver that allows you to play sounds (wav as well as midi) through your speaker.  I believe the driver is still available at the Microsoft download site.
0
 
LVL 18

Author Comment

by:deighton
Comment Utility
ClifABB - I can't find the down load - do you know the URL by any chance?
0
 
LVL 6

Expert Comment

by:clifABB
Comment Utility
I would like to point out, once again, that this is a 16-bit driver.  It's original intent was for Windows 3.x.  I cannot guarantee that it will work.

ftp://ftp.microsoft.com/Softlib/MSLFILES/SPEAK.EXE

Now, you need to install the driver. In Windows, from the Program Manager choose successively Main/Control Panel/Drivers/Add/Unlisted or updated drivers/(enter path of SPEAK.EXE)/PC Speaker. At this point some strange sounds come out as the driver is initialized. Change the settings to improve the sound quality on the various sounds: tada, chimes, etc. Click OK when you are finished and choose the Restart windows option.

Having installed the speaker driver, you will now get sounds whenever you start Windows, make a mistake, or exit Windows. If you do not want this, from the Main/Control Panel/Sounds menu, make sure there is no X next to "Enable System Sounds."
0
 
LVL 18

Author Comment

by:deighton
Comment Utility
Thanks for your help - I'll see how it goes!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

772 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

11 Experts available now in Live!

Get 1:1 Help Now