View Full Version : VB.net Timer help
I'm writing a program in VB.net. It requires the use of a timer to execute some code. However the timer module they have is not nearly as fast as I want it to be. I want to have a timer that has a resolution of a uS or faster. Is there a way to use a "Tick" of the system clock? Any help would be great
j
also known as MicroMan
primesuspect
25 Jul 2006, 09:29pm
your name is dumb. i'm going to change it back.
ps: i moved this into the programming forum where it will probably be better served.
airbornflght
25 Jul 2006, 09:46pm
I'm writing a program in VB.net. It requires the use of a timer to execute some code. However the timer module they have is not nearly as fast as I want it to be. I want to have a timer that has a resolution of a uS or faster. Is there a way to use a "Tick" of the system clock? Any help would be great
j
also known as MicroMan
well, I dont a timer, but I coded a 'time waster' in programming last year when I got bored, took like 5 minutes, and the speed was adjustable, but would be dependant on the processor speed.
I just coded two for loops and nested one inside the other, and made a few variables, our assignment was to move a ball around the screen, so I made the speed adjustable. Im sure this isnt what you are looking for, as I am a relative greenhorn to programming. I cant wait to get to college though, I am even excited about AP CS this year, a whole year focusing on java, it should be good.:D
Gargoyle
25 Jul 2006, 09:58pm
I'm writing a program in VB.net. It requires the use of a timer to execute some code. However the timer module they have is not nearly as fast as I want it to be. I want to have a timer that has a resolution of a uS or faster. Is there a way to use a "Tick" of the system clock? Any help would be great
j
also known as MicroMan
Someone gave me some code based on a function in kernel32, but I've only used it a couple of times, so I'm not sure if this is exactly what you're looking for. I don't think it'll make a differnece, but I used this in VBA(6).
Private Declare Function GetTickCount Lib "kernel32" () As Long
Then have something call GetTickCount and store the long integer it returns. Call GetTickCount again, and subtract the two numbers to get the difference.
It might be in mS, not uS, though.
lightnin
25 Jul 2006, 10:22pm
i've written kernel level code for unix that specifically references clock ticks. to my understanding this would be a kernel level thing in windows too, which is usually pretty complex.
you could build your own timer, i'm not sure if you could do real-time in VB though. you'll definitely need a knowledge of either real time programming or at least threaded programming, depending on what you want to do....
are you looking for some sort of scheduler or are you wanting to do something at a specific time? like is this a situation where you want something along the lines of
"run program A precisely 1450 june 2 2007"
or more like
"run program B as soon as program A gets done"
or a
"run program A for exactly 100 clock ticks then run program B for exactly 100 clock ticks then run A again"?
it's more like
after a certain number of ticks run the lines of code below. 1 tick would = 1uS or what ever the tick is. I just can't have the tick as 1mS, well it actually is about 10 to 20 ms when you sent the timer.interval value down to 1.
lightnin
26 Jul 2006, 12:57pm
hmm maybe something like this:
Option Explicit
Private Declare Function GetTickCount Lib "kernel32" () As Long
' Place this code in any Sub or Function
Dim lngStart As Long
Dim lngFinish As Long
Dim lngCounterOne As Long
Dim lngCounterTwo As Long
' Record the start "time"
lngStart = GetTickCount()
' Some process that you want to time
For lngCounterOne = 1 To 1000000
For lngCounterTwo = 1 To 5
Next lngCounterTwo
Next lngCounterOne
' Record the finish "time"
lngFinish = GetTickCount()
' Display the difference
MsgBox CStr(lngFinish - lngStart)
play around with that and see what you can do
hmm maybe something like this:
Option Explicit
Private Declare Function GetTickCount Lib "kernel32" () As Long
' Place this code in any Sub or Function
Dim lngStart As Long
Dim lngFinish As Long
Dim lngCounterOne As Long
Dim lngCounterTwo As Long
' Record the start "time"
lngStart = GetTickCount()
' Some process that you want to time
For lngCounterOne = 1 To 1000000
For lngCounterTwo = 1 To 5
Next lngCounterTwo
Next lngCounterOne
' Record the finish "time"
lngFinish = GetTickCount()
' Display the difference
MsgBox CStr(lngFinish - lngStart)
play around with that and see what you can do
How do I generate an event when a certain amount of ticks go by. I want to use it as a timer control. The problem is the timer control says you can set the interval to 1mS, but it actually is 20mS.
lightnin
26 Jul 2006, 03:53pm
if you want to get that granular, well, you're talking about system process scheduling. i doubt you can do it with vb, but there may be some kernel lib you could call on or something. i don't know much about windows system calls and google hasn't netted me anything useful yet but i'll keep looking.
--edit : didn't mean to include that link
lightnin
26 Jul 2006, 04:06pm
here's an api reference:
http://www.sysinternals.com/Information/NativeApi.html
or straight from the horse's mouth
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winprog/winprog/overview_of_the_windows_api.asp
Gargoyle
26 Jul 2006, 04:24pm
Filetime (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/about_time.asp) counts in 100 uS intervals.
I don't know anything about events, though.
vBulletin® v3.7.3, Copyright ©2000-2009, Jelsoft Enterprises Ltd.