[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Visual Basic question

Posted on 1997-07-05
1
Medium Priority
?
205 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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
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…
Suggested Courses

650 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