how can i make the program play a sound when my tmer is finished?

If txtSec.Text = 0 And txtMin.Text = 0 And txtHour.Text = 0 Then
    Timer1.Enabled = False
                                          <--------need sound to play here until cmd button pressed to stop it.
EndIf

First you have to delcare this API

Private Declare Function sndPlaySound Lib "winmm.dll" Alias _
"sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

after that

If txtSec.Text = 0 And txtMin.Text = 0 And txtHour.Text = 0 Then
    Timer1.Enabled = False
    result = sndPlaySound(location, 1)
EndIf

or you could try Beep function, it is make beep sound

thx man

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?

Private Declare Function sndPlaySound Lib "winmm.dll" Alias _
"sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

Private Sub Form_Load()
    result = sndPlaySound("C:\sound.wav",1)
End Sub

this code can only play wav file, it cannot play mp3 file, you have to convert mp3 file to wav file.

thx man.

this has saved me about 6 years worth of stress induced age.

so umm, sry 4 being annoying, but if this is my code, were does this piece go?

Private Sub SDOpt_Click(Index As Integer)
Dim Msg As String
Msg = "Spin Dry is"

Select Case SDOpt(Index).Index

    Case 0
        Msg = Msg & " On"
    Case 1
        Msg = Msg & " Off"
    End Select
Text7.Text = Msg
End Sub

Private Sub SSOpt_Click(Index As Integer)
Dim Msg As String
Msg = "Spin Speed is"

Select Case SSOpt(Index).Index

    Case 0
        Msg = Msg & " Fast"
    Case 1
        Msg = Msg & " Medium"
    Case 2
        Msg = Msg & " Slow"
    End Select
Text6.Text = Msg

End Sub

Private Sub WLOpt_Click(Index As Integer)
Dim Msg As String
Msg = "Water Level"

Select Case WLOpt(Index).Index

    Case 0
        Msg = Msg & " High"
    Case 1
        Msg = Msg & " Medium"
    Case 2
        Msg = Msg & " Low"
    End Select
Text4.Text = Msg
End Sub

Private Sub WTOpt_Click(Index As Integer)
Dim Msg As String
Msg = "Water Temp."

Select Case WTOpt(Index).Index

    Case 0
        Msg = Msg & " Hot"
    Case 1
        Msg = Msg & " Warm"
    Case 2
        Msg = Msg & " Cold"
    End Select
Text5.Text = Msg
End Sub

Private Sub Timer1_Timer()


If txtSec.Text = 0 And txtMin.Text = 0 And txtHour.Text = 0 Then
    Timer1.Enabled = False

    ElseIf txtSec.Text > 0 Then
        txtSec.Text = txtSec.Text - 1
    Else                                'if zero
        txtSec.Text = 59
    
            If txtMin.Text > 0 Then     'update mins
                txtMin.Text = txtMin.Text - 1
            Else
               'check if Hour is 0, and if it is, then stop timer, else continue
               txtMin.Text = 59
            
                If txtHour.Text > 0 Then     'update mins
                    txtHour.Text = txtMin.Text - 1
                Else
                   'check if Hour is 0, and if it is, then stop timer, else continue
                   txtHour.Text = 59
               End If
            
           End If
        
End If

End Sub

Private Sub startcmd_Click()
If startcmd.Caption = "Start Washing" Then
    Timer1.Enabled = True
    startcmd.Caption = "Pause / Stop"

ElseIf startcmd.Caption = "Pause / Stop" Then
    Timer1.Enabled = False
    startcmd.Caption = "Start Washing"
End If

End Sub

put this code on the top of your code

Private Declare Function sndPlaySound Lib "winmm.dll" Alias _
"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
    [B]result = sndPlaySound("C:\mysound.wav", 1)[/B]

thx man

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.

put this code on the top of your code

Private Declare Function sndPlaySound Lib "winmm.dll" Alias _
"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)

Sorry for my late reply. Because I haven't check DaniWeb for a month now. VB and C++ is much different. you cannot use VB code in C++. so it won't work. I am not good in C++ because I just start these few weeks. Here it is how to play sound in C++.

Put this code at the top of your code.

#pragma comment (lib, "winmm.lib")

you have to include some headers

#include <windows.h>
#include <mmsystem.h>

and use this function for play wave file.

sndPlaySound(filename, 1);

for more information about this function check this http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcewave/html/_wcesdk_win32_sndplaysound.asp

I hope this information is helpful.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.