Message 1 of 1
Help with PlaySound program
Not applicable
06-06-2008
04:17 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I hope you don't mind me mixing VBA with AutoLISP, but where I need help is in the VBA code. The program will only play sound files if the folder name and the sound file name do not have any spaces. I tried a few things like adding Chr(34) to the beginning and end of the path and filename. It still didn't work. But I know it works, because I can copy a sound file to my C:\Temp folder and rename the sound file without spaces and it works fine. I think the code to be revised is at the top of the VBA code, but I'm too new to this to know what to modify or change. Here's my AutoLISP and VBA code. The syntax of the AutoCAD command line is: (PlaySound "C:\\Windows\\Media\\tada.wav")
Thanks for your help. I really want this to work right.
Nugent
AutoLISP code:
[code]
(defun PlaySound (SoundFilename / Ext UserS5)
(if (setq Ext (vl-filename-extension SoundFilename))
(setq Ext (strcase Ext t))
)
(if (and (findfile SoundFilename)(member Ext (list ".wav" ".mp3" ".mid" ".cda" ".wma")))
(progn
(setq UserS5 (getvar "USERS5"))
(setvar "USERS5" SoundFilename)
(command "vbaload" "PlaySound.dvb")
(command "-vbarun" "thisdrawing.PlaySound")
(command "vbaunload" "PlaySound.dvb")
(setvar "USERS5" UserS5)
)
(princ (strcat "\n" SoundFilename " file not found or is not a valid sound file."))
)
(princ)
)
[/code]
VBA code:
[code]
Private Declare Function PlaySounds Lib "Winmm.dll" Alias "mciSendStringA" _
(ByVal strCommand As String, ByVal ReturnString As String, _
ByVal ReturnLength As Long, ByVal CallBack As Long) As Long
Function PlaySound()
Dim Filename As String
Dim lngReturn As Long
Dim str256 As String
str256 = String$(256, 0)
Filename = ThisDrawing.GetVariable("USERS5")
lngReturn = PlaySounds("Play " & Filename, str256, 255, 0)
End Function
[/code]
Thanks for your help. I really want this to work right.
Nugent
AutoLISP code:
[code]
(defun PlaySound (SoundFilename / Ext UserS5)
(if (setq Ext (vl-filename-extension SoundFilename))
(setq Ext (strcase Ext t))
)
(if (and (findfile SoundFilename)(member Ext (list ".wav" ".mp3" ".mid" ".cda" ".wma")))
(progn
(setq UserS5 (getvar "USERS5"))
(setvar "USERS5" SoundFilename)
(command "vbaload" "PlaySound.dvb")
(command "-vbarun" "thisdrawing.PlaySound")
(command "vbaunload" "PlaySound.dvb")
(setvar "USERS5" UserS5)
)
(princ (strcat "\n" SoundFilename " file not found or is not a valid sound file."))
)
(princ)
)
[/code]
VBA code:
[code]
Private Declare Function PlaySounds Lib "Winmm.dll" Alias "mciSendStringA" _
(ByVal strCommand As String, ByVal ReturnString As String, _
ByVal ReturnLength As Long, ByVal CallBack As Long) As Long
Function PlaySound()
Dim Filename As String
Dim lngReturn As Long
Dim str256 As String
str256 = String$(256, 0)
Filename = ThisDrawing.GetVariable("USERS5")
lngReturn = PlaySounds("Play " & Filename, str256, 255, 0)
End Function
[/code]