Q
Problem solve Get help with specific problems with your technologies, process and projects.

Need code that will count down and show a new question when time is up

I am working with VB.NET, and I am trying to write code that will do the following:

  • Allow a user to input the amount of seconds they have to answer a question.
  • If the user enters 5, there will a label that counts backwards 5, 4, 3, 2, 1; and then when 0 seconds is left, the form will show a different question. I

    was able to do this easily in VB6, but I am not able to get this to happen in VB.NET. Can you help?

    Public Class Form1
        Inherits System.Windows.Forms.Form
    
        Private m_CountDown As Int32 = 0
    
        Private Sub Button1_Click(ByVal sender As System.Object, _
                         ByVal e As System.EventArgs) Handles Button1.Click
            Try
                m_CountDown = Convert.ToInt32(TextBox1.Text, 10)
            Catch ex As FormatException
               ' Means it's not a number in the text box.
                m_CountDown = 0
            End Try
    
            If (m_CountDown > 0) Then
                Label1.Text = TextBox1.Text
                Button1.Enabled = False
                TextBox1.Enabled = False
                Timer1.Start()
            End If
        End Sub
    
        Private Sub Timer1_Tick(ByVal sender As Object, _ 
                           ByVal e As System.EventArgs) Handles Timer1.Tick
            m_CountDown = m_CountDown - 1
            Label1.Text = m_CountDown.ToString()
            If (m_CountDown = 0) Then
                TextBox1.Enabled = True
                Button1.Enabled = True
                Timer1.Stop()
            End If
        End Sub
    End Class 0) Then
                Label1.Text = TextBox1.Text
                Button1.Enabled = False
                TextBox1.Enabled = False
                Timer1.Start()
            End If
        End Sub
    
        Private Sub Timer1_Tick(ByVal sender As Object, _ 
                           ByVal e As System.EventArgs) Handles Timer1.Tick
            m_CountDown = m_CountDown - 1
            Label1.Text = m_CountDown.ToString()
            If (m_CountDown = 0) Then
                TextBox1.Enabled = True
                Button1.Enabled = True
                Timer1.Stop()
            End If
        End Sub
    End Class

  • Dig Deeper on VB code downloads

    Have a question for an expert?

    Please add a title for your question

    Get answers from a TechTarget expert on whatever's puzzling you.

    You will be able to add details on the next page.

    Start the conversation

    Send me notifications when other members comment.

    Please create a username to comment.

    -ADS BY GOOGLE

    SearchCloudComputing

    SearchSoftwareQuality

    TheServerSide.com

    SearchCloudApplications

    Close