473,320 Members | 1,950 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.

creating a visible timer in visual basic

I need some help with visual basic code, I need to create a timer that will be visible while playing a game, i know there is a timer in the tools that you pull over to the project and is hidden, and then i create a label on the page itself, the purpose is to show in seconds how long it takes to complete a game. what is the code that will link the timer with label so when i start my game you can see how many seconds it is taking.
Sep 13 '07 #1
2 4817
Killer42
8,435 Expert 8TB
I need some help with visual basic code, I need to create a timer that will be visible while playing a game, i know there is a timer in the tools that you pull over to the project and is hidden, and then i create a label on the page itself, the purpose is to show in seconds how long it takes to complete a game. what is the code that will link the timer with label so when i start my game you can see how many seconds it is taking.
(Note, I'm assuming VB6 here...)

One simple way would to store the value returned by the Timer() function (ignore the name, it's just a coincidence) when you start, then in the Timer1_Timer event, set the label caption to the difference between that original value and the current time.

For example, create a new form, add a timer (with Interval = 1000) and a label, and paste this into the code window...
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. DefLng A-Z
  3.  
  4. Private StartTime As Long
  5.  
  6. Private Sub Form_Load()
  7.   StartTime = Timer
  8. End Sub
  9.  
  10. Private Sub Timer1_Timer()
  11.   Label1.Caption = CLng(Timer - StartTime)
  12. End Sub
Sep 13 '07 #2
jamesd0142
469 256MB
Hi, see if this helps at all...

Display Time

Expand|Select|Wrap|Line Numbers
  1. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  2.   TimeToolStripMenuItem.Text = Now.ToLongTimeString() 'Display time in menu strip
  3. End Sub
Sep 14 '07 #3

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

Similar topics

0
by: Eli | last post by:
I'm developing a Visual Basic .Net app that interacts with Visio 2002. I have an event handler in VB to handle the Visio "SelectionChanged" event. This event handler is called when the event is...
3
by: rgb | last post by:
I've got Visual Studio 6.0 and I'm working on a Visual Basic applicaiton. There a couple parts that really require C. I've done C programming on a mainframe but nothing on a PC. So I'm trying to...
5
by: john | last post by:
I searched http://www.sellsbrothers.com. and could not find anything about this subject. How do I make C# User Controls Visible to Visual Basic 6.0 Applications? Thanks, John
6
by: smeagol | last post by:
Hi, is possible to create an OCX with .NET? I need to use a control (user control) in Visual Fox Pro, but the old fox doesn't accept usercontrols. Any help are welcome
2
by: DaWoE | last post by:
Hi all, I'm fairly new to ASP.NET. What i want to do is creat a online registration form. On the first step is getting the users details and the number of people he wants to register. Based on...
5
by: Nathan Sokalski | last post by:
I am trying to learn how to use the System.Timers.Timer control to perform an action every certain amount of time. However, the Elapsed event doesn't want to fire, but I can't figure out why. I...
3
by: zurg | last post by:
As far as I remember somewhere here was posted a question about Timer that was stoping at midnight(0.00 a.m.). I'm going to face this problem tommorow (implemeting a long working timer) so if...
5
by: dgardner | last post by:
This one has me stumped and I hope someone can help. I have a form with a button on it. When I click the button, I want a label named lblWait to be visible. (When the form opens, the label is...
2
by: =?Utf-8?B?U2Vhbk1hYw==?= | last post by:
I am familiar with how to use winsock in vb6 to create a network app. I'm trying to find a way to take the current vb6 app and create a windows service using system.net.sockets. How do you create...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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: 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...
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
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.