?
Solved

Visual Basic question

Posted on 1997-07-05
1
Medium Priority
?
203 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 

Accepted Solution

by:
acidos earned 140 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

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.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
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…

770 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