First off, I'm really new to development...sys-admin is really my thing. With that said, though, I'm hoping this is just a simmple mistake

I'm trying to write a nice little vb.net app with VS2010 to work as a photobooth.
The problem I've run into is, when the user hits the "Take Picture" button, I want the app to count down from 9 seconds (on the screen) before taking the photo. And I'm trying to keep my timer sub generic to use for other purposes (you'll see another timer call currently rem'd out)
However, the app is starting the timer, it counts down on the screen, but the rest of the code is not waiting for the timer to reach 0 before continuing on...it's taking the picture immediately.
Hopefully that made sense. Here's the pertinent code:

Private Sub btnSnap_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSnap.Click
        Dim intImageGroupNumber As Integer
        lblDirections.Text = "Get Ready to have your picture taken!"
        timercount = 9
        lblCountdown.Text = timercount.ToString()
        lblCountdown.Visible = True
        lblSeconds.Visible = True
        Timer1.Enabled = True
        Timer1.Start()
        CaptureImage()
        '  lblCountdown.Visible = False
        ' lblSeconds.Visible = False
        ' timercount = 3
        '  Timer1.Enabled = True
        PreviewVideo(PictureBox1)
    End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
        lblCountdown.Text = timercount.ToString()
        If timercount = 0 Then
            Timer1.Enabled = False
            Timer1.Stop()
        Else
            timercount -= 1
        End If
    End Sub

Move the CaptureImage and PreviewImage lines of code into the timer routine so that the picture gets taken when the timer gets to zero as in

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

    lblCountdown.Text = timercount.ToString()

    If timercount = 0 Then
        Timer1.Enabled = False
        CaptureImage()
        PreviewVideo(PictureBox1)
    Else
        timercount -= 1
    End If

End Sub

You don't need to use the Start and Stop methods of the timer. setting Enabled to True or False does just that.

This article has been dead for over six months. Start a new discussion instead.