Solved

Visual Basic question

Posted on 1997-07-05
1
198 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Updates not working for MS Windows 7 12 164
Visual Studio 2005 text editor 10 38
Spell Check in VB6 13 112
How to LOAD up a .NET Framework website with data? 2 54
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

813 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

9 Experts available now in Live!

Get 1:1 Help Now