Using a Timer to CountDown in VB.net

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • WorldIsEnding@googlemail.com

    Using a Timer to CountDown in VB.net

    How could i use the Timer component to count down from a certain
    number that i specify thats been entered into a variable?

    For example;
    Lets say i want to book a table at my local Snooker Club. When i go
    in, im given a set of balls and a table to play on - in turn, the
    person operating the console behind the bar switches on the tables
    lights and sets it so it will automatically turn off after, lets say,
    3 hours.

    Is there any way i could do this?
    If this doesnt make much sense, lemme know and ill try to explain it a
    little clearer >.<

    Cheers,

    3x0DuS

  • Tiago Salgado

    #2
    Re: Using a Timer to CountDown in VB.net

    Add the timer object, set Interval to 1000ms (1 second). Add a textbox and a
    button.

    Then u can use something like this:

    Dim myTime As Integer

    Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
    System.EventArg s) Handles Button1.Click
    myTime = TextBox1.Text
    Timer1.Enabled = True
    End Sub

    Private Sub Timer1_Tick(ByV al sender As System.Object, ByVal e As
    System.EventArg s) Handles Timer1.Tick
    TextBox1.Text = myTime - 1
    myTime = TextBox1.Text
    End Sub

    --

    Tiago Salgado



    Website da comunidade Portugal-a-Programar, a comunidade portuguesa de programação. Fórum de discussão de temas relacionados com programação e informática em geral, Portal de Downloads, Blogs, Wiki e Revista Programar.

    Portal da Revista PROGRAMAR, a revista portuguesa de programação


    <WorldIsEnding@ googlemail.comw rote in message
    news:1170860765 .731019.75880@k 78g2000cwa.goog legroups.com...
    How could i use the Timer component to count down from a certain
    number that i specify thats been entered into a variable?
    >
    For example;
    Lets say i want to book a table at my local Snooker Club. When i go
    in, im given a set of balls and a table to play on - in turn, the
    person operating the console behind the bar switches on the tables
    lights and sets it so it will automatically turn off after, lets say,
    3 hours.
    >
    Is there any way i could do this?
    If this doesnt make much sense, lemme know and ill try to explain it a
    little clearer >.<
    >
    Cheers,
    >
    3x0DuS
    >
    >

    Comment

    • rowe_newsgroups

      #3
      Re: Using a Timer to CountDown in VB.net

      On Feb 7, 10:06 am, WorldIsEnd...@g ooglemail.com wrote:
      How could i use the Timer component to count down from a certain
      number that i specify thats been entered into a variable?
      >
      For example;
      Lets say i want to book a table at my local Snooker Club. When i go
      in, im given a set of balls and a table to play on - in turn, the
      person operating the console behind the bar switches on the tables
      lights and sets it so it will automatically turn off after, lets say,
      3 hours.
      >
      Is there any way i could do this?
      If this doesnt make much sense, lemme know and ill try to explain it a
      little clearer >.<
      >
      Cheers,
      >
      3x0DuS
      This seems to simple, so I must be missing something but here it
      goes...

      On the timer.tick event decrement the variable and when it equals zero
      turn off the lights?

      Thanks,

      Seth Rowe

      Comment

      • Shane

        #4
        Re: Using a Timer to CountDown in VB.net

        Yeah, pretty much. I would check to see if the variable <= 0 instead
        of just zero as a butt covering.

        The example code above gives you the right idea, but the convesions
        between strings and integers may generate warnings in the compiler.
        The code should be casting integers to strings and strings to
        integers.

        Also, if you want to stop the timer event from firing, you'll want to
        set the enabled property to false.

        If MyTime <= 0 Then
        Timer1.Enabled = False
        ' Raise some event here or fire a subroutine
        EndIf

        Comment

        • Tiago Salgado

          #5
          Re: Using a Timer to CountDown in VB.net

          The code should have some modifications. I just give a simple code to give
          him a idea. :)

          --

          Tiago Salgado



          Website da comunidade Portugal-a-Programar, a comunidade portuguesa de programação. Fórum de discussão de temas relacionados com programação e informática em geral, Portal de Downloads, Blogs, Wiki e Revista Programar.

          Portal da Revista PROGRAMAR, a revista portuguesa de programação


          "Shane" <shane_news@yah oo.comwrote in message
          news:1170866044 .190615.63260@h 3g2000cwc.googl egroups.com...
          Yeah, pretty much. I would check to see if the variable <= 0 instead
          of just zero as a butt covering.
          >
          The example code above gives you the right idea, but the convesions
          between strings and integers may generate warnings in the compiler.
          The code should be casting integers to strings and strings to
          integers.
          >
          Also, if you want to stop the timer event from firing, you'll want to
          set the enabled property to false.
          >
          If MyTime <= 0 Then
          Timer1.Enabled = False
          ' Raise some event here or fire a subroutine
          EndIf
          >
          >

          Comment

          • rowe_newsgroups

            #6
            Re: Using a Timer to CountDown in VB.net

            Also, if you want to stop the timer event from firing, you'll want to
            set the enabled property to false.
            Or Timer1.Stop()

            Thanks,

            Seth Rowe


            On Feb 7, 11:34 am, "Shane" <shane_n...@yah oo.comwrote:
            Yeah, pretty much. I would check to see if the variable <= 0 instead
            of just zero as a butt covering.
            >
            The example code above gives you the right idea, but the convesions
            between strings and integers may generate warnings in the compiler.
            The code should be casting integers to strings and strings to
            integers.
            >
            Also, if you want to stop the timer event from firing, you'll want to
            set the enabled property to false.
            >
            If MyTime <= 0 Then
            Timer1.Enabled = False
            ' Raise some event here or fire a subroutine
            EndIf

            Comment

            Working...