Hello all, I'm trying to get a shot clock to work in my basketball game program. I've read a couple of tutorials but I'm still not getting it. I need it to start at 24 and go down to 0. As it is right now, it goes automatically to 0. Can anyone offer some advice? Thanks! -
Timer1.Enabled = True
-
Label78.Text = 24
-
Do Until Label78.Text = 0
-
If Label78.Text = 0 Then Timer1.Enabled = False And MessageBox.Show("Matchup Time is Up", "Basketball Mania", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1) Else
-
Label78.Text = Label78.Text - 1
-
Timer1.Interval = 24000
-
Loop
-
9 4248
What you need to look for is an event handler called Timer_Tick.
Go onto your design view (if the timer is a control placed int he design view) and click its event handlers, and double click the timer_Tick event handler.
this method which is created will be called every time tyour timer passes its time interval.
So you wont need that loop anymore, and the rest of the code has to be placed in that event handler
Is that the same as a timer? I tried using the timer but I can't place it on the form.
What you need to look for is an event handler called Timer_Tick.
Go onto your design view (if the timer is a control placed int he design view) and click its event handlers, and double click the timer_Tick event handler.
this method which is created will be called every time tyour timer passes its time interval.
So you wont need that loop anymore, and the rest of the code has to be placed in that event handler
Yes its the same control.
You can either declare a timer object from the form, or from the pure cs file
drop the timer control onto the form (a lower bar is then created, with the timer control sitting on it)
Ok, I have the timer on the form and I've set it at 24000 for 24 seconds. Is there any way to get a countdown actually to show when I run the program though? I don't necessary have to show it but I'd like to if there is a way. Thanks for your help!
Yes its the same control.
You can either declare a timer object from the form, or from the pure cs file
drop the timer control onto the form (a lower bar is then created, with the timer control sitting on it)
Set the interval on the timer the frequency you want the update to be.
Then set a TextBox on the display on timer tick.
When you start the timer store a DateTime dateTime = DateTime.Now.
Within the timer tick function when (dateTime.AddSeconds(24) < DateTime.Now) you can notify of your ending event
How do you set a textbox to timer tick? I'm looking in the properties box and I don't see that option.
Set the interval on the timer the frequency you want the update to be.
Then set a TextBox on the display on timer tick.
When you start the timer store a DateTime dateTime = DateTime.Now.
Within the timer tick function when (dateTime.AddSeconds(24) < DateTime.Now) you can notify of your ending event
Set the timer interval for 1000 (ms)
in your form class, create a variable called time_elapsed and set it to 24;
create the time tick event method and within that set the variable time_elapsed = time_elapsed - 1;
and in the next line
textBox.text = time_elapsed.ToString();
To check if the time has elapsed, check if time_elapsed == 0;
if it is so, set the timer's Enabled Property to false so that it stops ticking.
You cannot program by setting the properties of the control in desgin time.
Thanks for your help. I coded it like this: -
Timer1.Enabled = True
-
Dim time_elapsed As Integer
-
time_elapsed = 24
-
time_elapsed = time_elapsed - 1
-
Label80.Text = time_elapsed.ToString()
-
If time_elapsed = 0 Then Timer1.Enabled = False
-
It's immediately going to 0 though instead of counting down. Sorry for all the questions, I've never used the timer function before. Thank you.
Set the timer interval for 1000 (ms)
in your form class, create a variable called time_elapsed and set it to 24;
create the time tick event method and within that set the variable time_elapsed = time_elapsed - 1;
and in the next line
textBox.text = time_elapsed.ToString();
To check if the time has elapsed, check if time_elapsed == 0;
if it is so, set the timer's Enabled Property to false so that it stops ticking.
You cannot program by setting the properties of the control in desgin time.
Ok, I have the timer ...
Set the timer interval to 1000 (Which triggers each seconds)
Set a variable and its value to 24 (This is your countdown limit)
Enable the timer(enable when you want to start the countdown)
Inside Timer_Tick reduce the variable value -1(Start the countdown)
Then display it in label or textbox control
when variable limit is 0 then set the property enable = false to timer
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Jimmy Smits |
last post by:
Hi
I have been playing with some JS that I cut from another page. It is a NCAA
tournament bracket. When the user clicks on the submit button it sends the
predictions to a db I have created.
I got...
|
by: aegis |
last post by:
What is wall clock time? the standard doesn't define it
but I see its use in past posts on clc.
--
aegis
|
by: Charles M. Reinke |
last post by:
I'm using the function clock() to measure the run time of a program so that
I can compare among several different algorithms. My code looks like:
#include <stdio.h>
#include <stdlib.h>...
|
by: Peter Proost |
last post by:
Hi group,
I've got this bit of code (see below) which draws a basketball field in a
picturebox (width:198, height:368)
but now I was wondering what would be the easiest way to check inside the...
|
by: Chelonian |
last post by:
I'm considering trying to learn Python for a specific reason, and
hoped the group might help me get a sense for whether it would be worth
my time. The situation...
Me: total beginner w/ a...
|
by: pokemonmaster |
last post by:
How do i make a basketball bounce on python using coding........srry im kinda new to this......
|
by: DarkPhoenix739 |
last post by:
I have 3 classes: a Windows Form, a Game, and a Piece. The Game has a Piece, and the Windows Form has a Game. The Windows Form needs to be able to "get" the game's Piece, and view its data, but not...
|
by: Michelle Monty |
last post by:
Hello all,
I'm creating a basketball game with two teams of five players. I need to code the program to randomly pick one player from each team to match up. I've set my teams up but I can't...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |