adding sound

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2005
Posts: 62
Reputation: Slavrix is an unknown quantity at this point 
Solved Threads: 0
Slavrix Slavrix is offline Offline
Junior Poster in Training

adding sound

 
0
  #1
Oct 4th, 2005
how can i make the program play a sound when my tmer is finished?

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. If txtSec.Text = 0 And txtMin.Text = 0 And txtHour.Text = 0 Then
  2. Timer1.Enabled = False
  3. <--------need sound to play here until cmd button pressed to stop it.
  4. EndIf
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 464
Reputation: invisal is a jewel in the rough invisal is a jewel in the rough invisal is a jewel in the rough 
Solved Threads: 49
invisal's Avatar
invisal invisal is offline Offline
Posting Pro in Training

Re: adding sound

 
0
  #2
Oct 4th, 2005
First you have to delcare this API

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Declare Function sndPlaySound Lib "winmm.dll" Alias _
  2. "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

after that

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. If txtSec.Text = 0 And txtMin.Text = 0 And txtHour.Text = 0 Then
  2. Timer1.Enabled = False
  3. result = sndPlaySound(location, 1)
  4. EndIf

or you could try Beep function, it is make beep sound
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 62
Reputation: Slavrix is an unknown quantity at this point 
Solved Threads: 0
Slavrix Slavrix is offline Offline
Junior Poster in Training

Re: adding sound

 
0
  #3
Oct 5th, 2005
thx man
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 62
Reputation: Slavrix is an unknown quantity at this point 
Solved Threads: 0
Slavrix Slavrix is offline Offline
Junior Poster in Training

Re: adding sound

 
0
  #4
Oct 5th, 2005
does soundA get replaced by the name of the sound im using?



eg i the sound was called buzzer.mp3 what would the code look like?
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 464
Reputation: invisal is a jewel in the rough invisal is a jewel in the rough invisal is a jewel in the rough 
Solved Threads: 49
invisal's Avatar
invisal invisal is offline Offline
Posting Pro in Training

Re: adding sound

 
0
  #5
Oct 5th, 2005
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Declare Function sndPlaySound Lib "winmm.dll" Alias _
  2. "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
  3.  
  4. Private Sub Form_Load()
  5. result = sndPlaySound("C:\sound.wav",1)
  6. End Sub

this code can only play wav file, it cannot play mp3 file, you have to convert mp3 file to wav file.
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 62
Reputation: Slavrix is an unknown quantity at this point 
Solved Threads: 0
Slavrix Slavrix is offline Offline
Junior Poster in Training

Re: adding sound

 
0
  #6
Oct 5th, 2005
thx man.

this has saved me about 6 years worth of stress induced age.
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 62
Reputation: Slavrix is an unknown quantity at this point 
Solved Threads: 0
Slavrix Slavrix is offline Offline
Junior Poster in Training

Re: adding sound

 
0
  #7
Oct 6th, 2005
so umm, sry 4 being annoying, but if this is my code, were does this piece go?


Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub SDOpt_Click(Index As Integer)
  2. Dim Msg As String
  3. Msg = "Spin Dry is"
  4.  
  5. Select Case SDOpt(Index).Index
  6.  
  7. Case 0
  8. Msg = Msg & " On"
  9. Case 1
  10. Msg = Msg & " Off"
  11. End Select
  12. Text7.Text = Msg
  13. End Sub
  14.  
  15. Private Sub SSOpt_Click(Index As Integer)
  16. Dim Msg As String
  17. Msg = "Spin Speed is"
  18.  
  19. Select Case SSOpt(Index).Index
  20.  
  21. Case 0
  22. Msg = Msg & " Fast"
  23. Case 1
  24. Msg = Msg & " Medium"
  25. Case 2
  26. Msg = Msg & " Slow"
  27. End Select
  28. Text6.Text = Msg
  29.  
  30. End Sub
  31.  
  32. Private Sub WLOpt_Click(Index As Integer)
  33. Dim Msg As String
  34. Msg = "Water Level"
  35.  
  36. Select Case WLOpt(Index).Index
  37.  
  38. Case 0
  39. Msg = Msg & " High"
  40. Case 1
  41. Msg = Msg & " Medium"
  42. Case 2
  43. Msg = Msg & " Low"
  44. End Select
  45. Text4.Text = Msg
  46. End Sub
  47.  
  48. Private Sub WTOpt_Click(Index As Integer)
  49. Dim Msg As String
  50. Msg = "Water Temp."
  51.  
  52. Select Case WTOpt(Index).Index
  53.  
  54. Case 0
  55. Msg = Msg & " Hot"
  56. Case 1
  57. Msg = Msg & " Warm"
  58. Case 2
  59. Msg = Msg & " Cold"
  60. End Select
  61. Text5.Text = Msg
  62. End Sub
  63.  
  64. Private Sub Timer1_Timer()
  65.  
  66.  
  67. If txtSec.Text = 0 And txtMin.Text = 0 And txtHour.Text = 0 Then
  68. Timer1.Enabled = False
  69.  
  70. ElseIf txtSec.Text > 0 Then
  71. txtSec.Text = txtSec.Text - 1
  72. Else 'if zero
  73. txtSec.Text = 59
  74.  
  75. If txtMin.Text > 0 Then 'update mins
  76. txtMin.Text = txtMin.Text - 1
  77. Else
  78. 'check if Hour is 0, and if it is, then stop timer, else continue
  79. txtMin.Text = 59
  80.  
  81. If txtHour.Text > 0 Then 'update mins
  82. txtHour.Text = txtMin.Text - 1
  83. Else
  84. 'check if Hour is 0, and if it is, then stop timer, else continue
  85. txtHour.Text = 59
  86. End If
  87.  
  88. End If
  89.  
  90. End If
  91.  
  92. End Sub
  93.  
  94. Private Sub startcmd_Click()
  95. If startcmd.Caption = "Start Washing" Then
  96. Timer1.Enabled = True
  97. startcmd.Caption = "Pause / Stop"
  98.  
  99. ElseIf startcmd.Caption = "Pause / Stop" Then
  100. Timer1.Enabled = False
  101. startcmd.Caption = "Start Washing"
  102. End If
  103.  
  104. End Sub
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 464
Reputation: invisal is a jewel in the rough invisal is a jewel in the rough invisal is a jewel in the rough 
Solved Threads: 49
invisal's Avatar
invisal invisal is offline Offline
Posting Pro in Training

Re: adding sound

 
0
  #8
Oct 6th, 2005
put this code on the top of your code
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Declare Function sndPlaySound Lib "winmm.dll" Alias _
  2. "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

and

If txtSec.Text = 0 And txtMin.Text = 0 And txtHour.Text = 0 Then
    Timer1.Enabled = False
    result = sndPlaySound("C:\mysound.wav", 1)
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 62
Reputation: Slavrix is an unknown quantity at this point 
Solved Threads: 0
Slavrix Slavrix is offline Offline
Junior Poster in Training

Re: adding sound

 
0
  #9
Oct 6th, 2005
thx man
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 1
Reputation: cjh_wc is an unknown quantity at this point 
Solved Threads: 0
cjh_wc cjh_wc is offline Offline
Newbie Poster

Re: adding sound

 
0
  #10
Jan 16th, 2006
hi invisal, will u mind helping me to slove this problem? i will thanks u alots. my problem is quite same as i want to play recored sound in wav form in C++ so don't mind helping me?

as wat u have say putting this code on top of rhe whole program rite but i using C++ it come up with the following problem which is under the code that u have post. don't mind take a look on it n see whether u can help me. thanks.

[QUOTE=invisal]put this code on the top of your code
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Declare Function sndPlaySound Lib "winmm.dll" Alias _
  2. "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

n do i need to declare the result under which variable? like int, float, unsign char...... or just leave it whitout any declaration?

result = sndPlaySound("C:\mysound.wav", 1)

or do u have any other better way for C++?

--------------------Configuration: Vsdemo - Win32 Debug--------------------
Compiling...
VC.cpp

C:\KangyingCong\Web_C++LASTday\C++Vision\VC.cpp(50) : error C2146: syntax error : missing ';' before identifier 'Declare'

C:\KangyingCong\Web_C++LASTday\C++Vision\VC.cpp(50) : error C2501: 'Private' : missing storage-class or type specifiers

C:\KangyingCong\Web_C++LASTday\C++Vision\VC.cpp(50) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

VC.exe - 3 error(s), 0 warning(s)
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum


Views: 4539 | Replies: 10
Thread Tools Search this Thread



Tag cloud for Visual Basic 4 / 5 / 6
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC