Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Nov 2002
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Getting millisecs in Visual Basic

    I would like to be able to access the time in Visual Basic in millisecs.
    I was using the timer control set to an interval of 1, but I found out it doesn't actually fire every .001 seconds.

    The program tests reaction time to an event, so I was thinking of subtracting the time the program prompts the user from the time the user responds.

    Everyone I ask says it should be easy to find but I am having no luck.

    Thanks

  • #2
    New to the CF scene
    Join Date
    Nov 2002
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I tried this a couple times and it seems to work. I am not familiar with the first line in this code - can someone give me some more information on it?


    Private Declare Function GetTickCount Lib "kernel32" () As Long
    Private lngStart As Long

    Private Sub cmdStart_Click()
    lngStart = GetTickCount()
    End Sub

    Private Sub cmdStop_Click()
    MsgBox CStr(GetTickCount() - lngStart) & " milliseconds"
    MsgBox lngStart
    End Sub

  • #3
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    I'm not 100% sure on this but I think it is everytime windows "ticks" or refreshes. And if you don't know, 1 millisecond is a 1/1000 of a second.

    The declare function is to access the windows kernel and obtain the tick count. That code should work.

  • #4
    New to the CF scene
    Join Date
    Nov 2002
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Does anyone know how reliable this code is? I mean, if Windows is running alot of programs will this code still give me an accurate elasped time?

  • #5
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Well this lander game that I found and significantly improved operates based on the tick count, so test it out. I've found it to be very relieble but you never know.

    www.kurannet.com/landerv3.zip
    OracleGuy


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •