Click here to Skip to main content
15,919,879 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to use a timer to record until the value of a progressbar drops below a certain level then save. The problem I have is it saves each recording several times. The two timers at the bottom are for recording and saving.

Public Sub Record()
        Dim result As Long
        Try
            result = mciSendString("open new Type waveaudio Alias recsound", "", 0, Nothing)
            result = mciSendString("record recsound", "", 0, 0)
        Catch ex As Exception
        End Try
    End Sub

    Public Sub StopAndSave()
        Dim formatteddate As String
        formatteddate = DateTime.Now.ToString("MMddyyyyHHmmss")
        Dim Filetosave As String = "save recsound " & ("c:\" & formatteddate & ".wav")
        mciSendString(Filetosave, "", 0, 0)
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If Me.ProgressBar1.Value > 80 Then
            Record()
        End If
    End Sub

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        If Me.ProgressBar1.Value < 80 Then
            StopAndSave()
        Else
        End If
    End Sub
Posted
Updated 21-Jul-10 12:44pm
v2
Comments
Dalek Dave 21-Jul-10 18:44pm    
Edited to put in code block

When you save, you need to stop your timer.

Why have two timers, anyhow, that makes no sense at all.

What happens if the progress bar is at 80 ?
 
Share this answer
 
I tried many different variations including only one timer but couldn't figure it out.

Any idea how to word with one timer?
 
Share this answer
 
Comments
Christian Graus 21-Jul-10 19:14pm    
Don't push 'answer' to ask more questions. You can comment, like I did here. You make your one timer do both time checks, and you call it's Stop method before you call the save method.
I think I got it. This seems to work perfect

VB
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
       If Me.ProgressBar1.Value >= 80 Then
           Record()
       ElseIf Me.ProgressBar1.Value < 80 Then
           Me.Timer1.Enabled = True
       End If
   End Sub
   Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
       If Me.ProgressBar1.Value < 80 Then
           Me.Timer1.Enabled = False
           StopAndSave()
           CloseAudio()
       Else
       End If
       Me.Timer1.Enabled = True
   End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900