VB.net Timer help

jj Sterling Heights, MI Icrontian
edited July 2006 in Internet & Media
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

Comments

  • primesuspectprimesuspect Beepin n' Boopin Detroit, MI Icrontian
    edited July 2006
    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.
  • airbornflghtairbornflght Houston, TX Icrontian
    edited July 2006
    j wrote:
    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
  • GargGarg Purveyor of Lincoln Nightmares Icrontian
    edited July 2006
    j wrote:
    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.
  • edited July 2006
    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"?
  • jj Sterling Heights, MI Icrontian
    edited July 2006
    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.
  • edited July 2006
    hmm maybe something like this:

    [PHP]
    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)
    [/PHP]


    play around with that and see what you can do
  • jj Sterling Heights, MI Icrontian
    edited July 2006
    lightnin wrote:
    hmm maybe something like this:

    [PHP]
    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)
    [/PHP]


    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.
  • edited July 2006
    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
  • GargGarg Purveyor of Lincoln Nightmares Icrontian
    edited July 2006
    Filetime counts in 100 uS intervals.

    I don't know anything about events, though.
Sign In or Register to comment.