VB Timer Failed VB.net

Having serious bug issues with timer

Page 1 of 1

2 Replies - 1289 Views - Last Post: 21 November 2009 - 10:54 AM Rate Topic: -----

#1 coaster3000  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 99
  • Joined: 28-August 08

VB Timer Failed VB.net

Posted 21 November 2009 - 09:54 AM

I have been working on a project for fun but i am also publishing on this site. Its a torpia toolbar. AKA a toolbar meant for the game torpia. And i am seriously getting angry at how many bugs are in this SINGLE! object!

I would like some help on this one Please. This is no homework assignment i dont even have programming in my school <_< which stinks. So this is not like cheating or anything. I only code for the sole purpose of being creative. Enough of that. I programmed it so that it will debug super fast. Each second is counted every 1 mili second for rapid debugging. so i can find out in the hours section of where it stopps counting properly. It will stopped the timer. It will then bring a message that it has reached a error on counting. And then since the timer is stopped the app will stay on the current time it stopped at. The time it shows is 01:01:09

which is 1 hour 1 minute and 9 seconds. so here is the code. I have already thought of it already being fixed as of this line for detecting it.
		ElseIf (var_hours < 10) And (var_minutes < 10) And (var_minutes > 9) Then
			Timer_time.Text = "0" & var_hours & ":0" & var_minutes & ":" & var_sec


but i guess not so here is full source on that timer_tick section

	Private Sub timersec1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timersec1.Tick
		var_sec = var_sec + 1
		If var_sec = 60 Then
			var_sec = 0
			var_minutes = var_minutes + 1
		End If
		If var_minutes = 60 Then
			var_minutes = 0
			var_hours = var_hours + 1
		End If
		If (var_hours = 0) And (var_minutes = 0) And (var_sec < 10) Then
			Timer_time.Text = "00:00:0" & var_sec
		ElseIf (var_hours = 0) And (var_minutes = 0) And (var_sec > 9) Then
			Timer_time.Text = "00:00:" & var_sec
		ElseIf (var_hours = 0) And (var_minutes < 10) And (var_minutes <> 0) And (var_sec < 10) Then
			Timer_time.Text = "00:0" & var_minutes & ":0" & var_sec
		ElseIf (var_hours = 0) And (var_minutes < 10) And (var_minutes <> 0) And (var_sec > 9) Then
			Timer_time.Text = "00:0" & var_minutes & var_sec
		ElseIf (var_hours = 0) And (var_minutes > 9) And (var_sec < 10) Then
			Timer_time.Text = "00:" & var_minutes & ":0" & var_sec
		ElseIf (var_hours = 0) And (var_minutes > 9) And (var_sec > 9) Then
			Timer_time.Text = "00:" & var_minutes & ":" & var_sec
		ElseIf (var_hours < 10) And (var_hours <> 0) And (var_minutes = 0) And (var_sec = 0) Then
			Timer_time.Text = "0" & var_hours & ":00:00"
		ElseIf (var_hours < 10) And (var_hours <> 0) And (var_minutes = 0) And (var_sec < 10) Then
			Timer_time.Text = "0" & var_hours & ":00:" & "0" & var_sec
		ElseIf (var_hours < 10) And (var_hours <> 0) And (var_minutes < 10) And (var_sec = 0) Then
			Timer_time.Text = "0" & var_hours & ":0" & var_minutes & ":00"
		ElseIf (var_hours < 10) And (var_hours <> 0) And (var_minutes < 10) And (var_sec < 10) Then
			Timer_time.Text = "0" & var_hours & ":0" & var_minutes & ":0" & var_sec
		ElseIf (var_hours < 10) And (var_hours <> 0) And (var_minutes > 9) And (var_sec < 10) Then
			Timer_time.Text = "0" & var_hours & ":" & var_minutes & ":0" & var_sec
		ElseIf (var_hours < 10) And (var_hours <> 0) And (var_minutes > 9) And (var_sec > 9) Then
			Timer_time.Text = "0" & var_hours & ":" & var_minutes & var_sec
		ElseIf (var_hours > 9) And (var_minutes < 10) And (var_minutes <> 0) And (var_sec < 10) And (var_sec <> 0) Then
			Timer_time.Text = var_hours & ":0" & var_minutes & ":0" & var_sec
		ElseIf (var_hours > 9) And (var_minutes > 9) And (var_sec < 10) And (var_sec <> 0) Then
			Timer_time.Text = var_hours & ":" & var_minutes & ":0" & var_sec
		ElseIf (var_hours > 9) And (var_minutes = 0) And (var_sec = 0) Then
			Timer_time.Text = var_hours & ":00:00"
		ElseIf (var_hours > 9) And (var_minutes = 0) And (var_sec < 10) And (var_sec <> 0) Then
			Timer_time.Text = var_hours & ":00:0" & var_sec
		ElseIf (var_hours > 9) And (var_minutes < 10) And (var_sec = 0) Then
			Timer_time.Text = var_hours & ":0" & var_minutes & ":00"
		ElseIf (var_hours > 9) And (var_minutes > 9) And (var_sec = 0) Then
			Timer_time.Text = var_hours & ":" & var_minutes & ":00"
		ElseIf (var_hours > 9) And (var_minutes > 9) And (var_sec < 10) Then
			Timer_time.Text = var_hours & ":" & var_minutes & ":0" & var_sec
		ElseIf (var_hours > 9) And (var_minutes < 10) And (var_sec < 10) Then
			Timer_time.Text = var_hours & ":0" & var_minutes & ":0" & var_sec
		ElseIf (var_hours > 9) And (var_minutes > 9) And (var_sec < 10) Then
			Timer_time.Text = var_hours & ":" & var_minutes & ":0" & var_sec
		ElseIf (var_hours > 9) And (var_minutes > 9) And (var_sec > 9) Then
			Timer_time.Text = var_hours & ":" & var_minutes & ":" & var_sec
		ElseIf (var_hours < 10) And (var_minutes = 0) And (var_sec > 9) Then
			Timer_time.Text = "0" & var_hours & ":00:" & var_sec
		ElseIf (var_hours < 10) And (var_minutes < 10) And (var_sec = 0) Then
			Timer_time.Text = "0" & var_hours & ":0" & var_minutes & ":00"
		ElseIf (var_hours < 10) And (var_minutes < 10) And (var_sec < 10) Then
			Timer_time.Text = "0" & var_hours & ":0" & var_minutes & ":0" & var_sec
		ElseIf (var_hours < 10) And (var_minutes > 9) And (var_sec = 0) Then
			Timer_time.Text = "0" & var_hours & ":" & var_minutes & ":00"
		ElseIf (var_hours < 10) And (var_minutes > 9) And (var_sec < 10) Then
			Timer_time.Text = "0" & var_hours & ":" & var_minutes & ":0" & var_sec
		ElseIf (var_hours < 10) And (var_minutes > 9) And (var_sec > 9) Then
			Timer_time.Text = "0" & var_hours & ":" & var_minutes & ":" & var_sec
		ElseIf (var_hours < 10) And (var_minutes < 10) And (var_minutes > 9) Then
			Timer_time.Text = "0" & var_hours & ":0" & var_minutes & ":" & var_sec
		Else
			timersec1.Enabled = False
			MsgBox("Error occured Timer error. For stop watch! timer stopped hit reset to start back up Unknown error. Something with hour / minute / second detection", MsgBoxStyle.Critical, "WARNING")
		End If
		Do While (var_hours = 99)
			timersec1.Enabled = False
			MsgBox("You have been on for a long time. Why not try going outside or SLEEPING!!! This is the max limit the stop watch can go 99 Hours!!! hit reset to start back up! Timer stopped", MsgBoxStyle.Exclamation, "WOW!!!")


		Loop
	End Sub


It is seriously getting on my nerves

i have been working on this for days (The whole program) but this time for 2 days for just debugging this timer! so please i beg you to help me. (Joke on this issue) Its like it came from hell to torture me from bugs!!!

i was also thinking of posting a snippet of this if there is none already. Because this specific code is supposed to keep the 00 even if it is just like a number below 10 in the variable but :-\ i guess not if this will not get debugged.
Also since there was a limit in this thing of only hours i put a stop code for when it reached 99 hours. and displays a funny message :)
edit:
just a note This is a massive project for me i guess :)

This post has been edited by coaster3000: 21 November 2009 - 09:55 AM


Is This A Good Question/Topic? 0
  • +

Replies To: VB Timer Failed VB.net

#2 SixOfEleven  Icon User is offline

  • using Caffeine;
  • member icon

Reputation: 945
  • View blog
  • Posts: 6,342
  • Joined: 18-October 08

Re: VB Timer Failed VB.net

Posted 21 November 2009 - 10:00 AM

Check out this thread here on DIC on how to work with timers in VB.NET. It shows how to keep a running total of elapsed time in milliseconds and convert it to seconds, minutes, hours and even days. I think it might help you out with your problem. It also uses the Stopwatch class to keep track of the elapsed time which is much more accurate then using the ticks of a timer. I hope that it helps you out.

http://www.dreaminco...topic139748.htm
Was This Post Helpful? 0
  • +
  • -

#3 crepitus  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 85
  • View blog
  • Posts: 383
  • Joined: 08-September 09

Re: VB Timer Failed VB.net

Posted 21 November 2009 - 10:54 AM

You're re-inventing the wheel. Note the start time, then in the tick event work out the TimeSpan difference between Now and the StartTime. Then display it. As the timer is very inaccurate you can check every 1/10th of a second to see if time has moved on a whole second since the last update...

Option Strict On
Option Explicit On

Public Class Form1

	Friend WithEvents Timer1 As New Timer With {.Interval = 100, .Enabled = True}
	Private startTime As DateTime
	Private lastSec As Integer
	Private Const format As String = "{0:D2}:{1:D2}:{2:D2}"

	Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
		startTime = Now
		lastSec = startTime.Second
	End Sub

	Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
		Dim elapsedTime As TimeSpan = Now - startTime
		' The timer is inacurate, so we'll check every 10th of a second if this is a new second or not...
		If lastSec = elapsedTime.Seconds Then Exit Sub
		lastSec = elapsedTime.Seconds
		Me.Text = String.Format(format, elapsedTime.Hours, elapsedTime.Minutes, elapsedTime.Seconds)
	End Sub

End Class

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1