Solved

Visual Basic question

Posted on 1997-07-05
1
199 Views
Last Modified: 2013-11-25
Am I missing something, or is it a W95 problem...

When I have an embedded OLE object in my database, and it is pulled up into an OLE container in my form, I can open all others that I've tried - Excel, Visio, Notepad, MIDI, BMP etc...

BUT if the embedded document is a WAV file, I get an 'OLE Automation Error' message box, an error 'beep' then the sound plays.

About 50% of the time, my app is tied up after I clear the message box.

I obviously suspect the SNDREC32 app, but does anyone have anything specific, or a solution to this ?

Regards
MC

mcoop@pop.jaring.my
0
Comment
Question by:mcoop
1 Comment
 

Accepted Solution

by:
acidos earned 70 total points
ID: 1428019
 This is a common problem.  Forget trying to OLE in a WAV file, do this:

1) Open your programs module file (or create one if it doesn't have one), and then insert this:

Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Public Declare Function waveOutGetNumDevs Lib "winmm" () As Long

Global Const SND_SYNC = &H0 'just after the sound is ended exit function
Global Const SND_ASYNC = &H1 'just after the beginning of the sound exit function
Global Const SND_NODEFAULT = &H2 'if the sound cannot be found no error message
Global Const SND_LOOP = &H8 'repeat the sound until the function is called again
Global Const SND_NOSTOP = &H10 'if currently a sound is played the function will return without playing the selected sound

Global Const Flags& = SND_ASYNC Or SND_NODEFAULT


2) Create a public sub in the general declarations part of the same module with a name like Play, Sound, Wav, ect. and enter this code into it:

Public Sub Play(SoundFileName As String)
    Dim Crapper As Long
    Crapper = waveOutGetNumDevs()
    If Crapper > 0 Then   'There is at least one sound device.
    Crapper& = sndPlaySound(SoundFileName, Flags&)
    Else
      Beep
    End If

End Sub

3) To play a wav file just type Play(path).  ie: to play a wav file in directory c:\media named sound.wav you would type:

Play("c:\media\sound.wav")

NOTE: Commands after this procedure call are executed BEFORE the wav file is finished playing.  If you want to wait for the wav file to stop playing before the code continues, you need 2 things:

1) The estimated time in seconds (rounded down) of the wav file [this example only works if the wav file is less than 60 seconds. Feel free to modify this code if you wish]

2) Create a new public sub in yer module like Pause.  ie:

Public Sub Pause(Numb As Integer)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
'               Pauses for a specific amount of seconds
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Dim tot As Integer
    Dim now As String
    Dim lat As String
    now = Time
    now = Left(now, Len(now) - 3)
    now = Right(now, Len(now) - 5)
    lat = Int(now) + Numb
    If lat > 60 Then lat = lat - 60
    Do While tot <> lat
        now = Time
        now = Left(now, Len(now) - 3)
        tot = Right(now, Len(now) - 5)
    Loop
End Sub


  Now, to pause for x amount of seconds, simply type Pause(x).  ie:  to pause for 5 seconds type:

Pause(5)

  To play a sound file c:\media\sound.wav which lasts 15.x seconds and to have the program wait till the sound file is done playing before executing the other code, type:

Play("c:\media\sound.wav")
Pause(15)

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

838 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