473,320 Members | 1,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

Feb 7 '07 #1
5 34810
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(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
myTime = TextBox1.Text
Timer1.Enabled = True
End Sub

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

--

Tiago Salgado

http://weblogs.pontonetpt.com/tiagosalgado
http://www.foruns.org
http://www.portugal-a-programar.org
http://www.revista-programar.info

<Wo***********@googlemail.comwrote in message
news:11*********************@k78g2000cwa.googlegro ups.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

Feb 7 '07 #2
On Feb 7, 10:06 am, WorldIsEnd...@googlemail.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

Feb 7 '07 #3
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

Feb 7 '07 #4
The code should have some modifications. I just give a simple code to give
him a idea. :)

--

Tiago Salgado

http://weblogs.pontonetpt.com/tiagosalgado
http://www.foruns.org
http://www.portugal-a-programar.org
http://www.revista-programar.info

"Shane" <sh********@yahoo.comwrote in message
news:11*********************@h3g2000cwc.googlegrou ps.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

Feb 7 '07 #5
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...@yahoo.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
Feb 7 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: ray | last post by:
Hi, I just wrote a windows service application to call a function of another object periodically. I used System.Server.Timer and I found that it works fine within the first 2 hours but the...
0
by: dave | last post by:
In A2000 I have a table containing a memo field. There is an unbound form for entering text, and there can be lots of it. When the form opens there is a function to grab the data from the table and...
2
by: id santhosh via .NET 247 | last post by:
(Type your message here) i will have to conduct a online test using timer? how can i implement? please send some codes also..please help.. -------------------------------- From: id santhosh ...
4
by: Rich | last post by:
Hello, I am trying to measure the elapsed time between 2 processes. If I declare startTime As Double, endTime as Double and say startTime = Timer .... process1 ....
4
by: kai | last post by:
Hi, I try to referesh my asp.net 2.0 page every minite using timer control, but cannot find code for refresh. Please help? Thanks Kai
2
by: Amit Dedhia | last post by:
Hi I am developing a scientific application which has moderate level image processing involved. In my application, there is a main application form which invokes another form. When this form...
3
by: stevemcc | last post by:
I am using a timer in an alarm clock application I am writing. I don't seem to understand how to use the timer. import threading class MyClass: def __init__(self): ...
1
by: baillie11 | last post by:
Hi all, im in a pickle. I have a created a Texas Holdem Poker Timer for my Friday night Poker games. I am using an MS Access Database to store and retrieve my saved blind levels with the round...
2
by: CommonElements | last post by:
Hi, 1. I am using Visual Studio.NET 2005 C# Win Form 2. I have setup a database connection to my Access Database using ADO.NET 3. On my system timer I have the following code to execute every 1...
6
by: dantz | last post by:
HI everyone, I hope someone can help me on this. I have form application that has 3 Timers that does an animation (changing an image for every interval) Each image are loaded at start of...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.