473,323 Members | 1,547 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,323 software developers and data experts.

VB.NET App: Shot Clock in Basketball Game

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!

Expand|Select|Wrap|Line Numbers
  1. Timer1.Enabled = True
  2.         Label78.Text = 24
  3.         Do Until Label78.Text = 0
  4.             If Label78.Text = 0 Then Timer1.Enabled = False And MessageBox.Show("Matchup Time is Up", "Basketball Mania", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1) Else 
  5.             Label78.Text = Label78.Text - 1
  6.             Timer1.Interval = 24000
  7.         Loop 
  8.  
Dec 19 '07 #1
9 4248
Shashi Sadasivan
1,435 Expert 1GB
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
Dec 19 '07 #2
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
Dec 19 '07 #3
Shashi Sadasivan
1,435 Expert 1GB
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)
Dec 19 '07 #4
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)
Dec 19 '07 #5
sigil
4
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
Dec 19 '07 #6
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
Dec 20 '07 #7
Shashi Sadasivan
1,435 Expert 1GB
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.
Dec 20 '07 #8
Thanks for your help. I coded it like this:
Expand|Select|Wrap|Line Numbers
  1. Timer1.Enabled = True
  2.         Dim time_elapsed As Integer
  3.         time_elapsed = 24
  4.         time_elapsed = time_elapsed - 1
  5.         Label80.Text = time_elapsed.ToString()
  6.         If time_elapsed = 0 Then Timer1.Enabled = False
  7.  
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.
Dec 26 '07 #9
CyberSoftHari
487 Expert 256MB
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
Dec 26 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

8
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...
12
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
6
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>...
3
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...
4
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...
2
by: pokemonmaster | last post by:
How do i make a basketball bounce on python using coding........srry im kinda new to this......
5
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...
1
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...
0
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...
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...
1
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...
1
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....
0
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
0
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...
0
isladogs
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...

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.