Results 1 to 14 of 14

Thread: Timers [Faster Time]

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2006
    Posts
    51

    Timers [Faster Time]

    Hello,

    I am making an auto-clicking program, and there are currently 5 different time settings.

    Hours, Minutes, Seconds, 1/10 of a Second, and 1/10 of a Second.

    I have some uses for this program that require IMEADIATE clicking, as in 1/1000 or 1/10 000 of a second. I have knoticed that on the timer interval, there is not much differance between 1 and 10... I tested this out on labels. Is there any files that i can include or any code i could use to achieve these faster times?

    (I would use Form_Load, but i need to have it in an area where i can controll it.)

    Thanks
    ~Cody Woolaver

  2. #2
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465

    Re: Timers [Faster Time]

    The Timer has a maximum tick count of about 64 ticks per second. Sometimes this fluxuates a bit, but in general, that's as fast as it goes.

  3. #3
    New Member
    Join Date
    Nov 2006
    Posts
    10

    Re: Timers [Faster Time]

    try something like
    VB Code:
    1. 'module
    2. Public Declare Function timeGetTime Lib "winmm.dll" () As Long
    3.  
    4. Public Sub Wait(TimeOut As Long)
    5.  Dim TimeNow As Long
    6.  TimeNow = timeGetTime()
    7.  Do
    8.    DoEvents
    9.  Loop While TimeNow + TimeOut > timeGetTime()
    10. End Sub
    11. 'in button or somin
    12. do until (bStop = True)
    13.   wait 1
    14.   Click
    15. loop

    'this may have errors, and make ur click send the mouseevent to click or however ur doing it

  4. #4
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Timers [Faster Time]

    i don't believe timeGetTime is any more accurate than GetTickCount, ±16 milliseconds (probably worse)

    if you want millisecond accuracy you have to use the QueryPerformance APIs.

    i think the only way you can better than millisecond accuracy is to use a hardware timer.

  5. #5
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Timers [Faster Time]

    Here's an example of the QueryPerformance API's. This is idle for accurate time:

    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function QueryPerformanceFrequency Lib "kernel32" (lpFrequency As Currency) As Long
    4. Private Declare Function QueryPerformanceCounter Lib "kernel32" (lpCount As Currency) As Long
    5.  
    6. Private Tick_Count As Currency
    7. Private Time As Currency
    8.  
    9. Private Sub Form_Activate()
    10.  
    11.     AutoRedraw = True
    12.    
    13.     ScaleMode = 3
    14.    
    15.     QueryPerformanceFrequency Tick_Count
    16.    
    17.     Do
    18.    
    19.         DoEvents
    20.        
    21.         Cls
    22.  
    23.         QueryPerformanceCounter Time
    24.  
    25.         Print Time / Tick_Count
    26.        
    27.                
    28.     Loop
    29.  
    30. End Sub

  6. #6

    Thread Starter
    Member
    Join Date
    Nov 2006
    Posts
    51

    Re: Timers [Faster Time]

    Heh ^^;

    Sorry, im not a huge expert in visual basic. I understand those are Modules, but i could use more explination on what they actchually do. and is there anyway that i could get something like a DLL to calculate faster speed? or something?

    Thanks alot guys ^^;
    ~Cody

  7. #7
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Timers [Faster Time]

    You won't need to. The Query API's are 1 millisecond accurate. The timeGetTime and GetTickCount API's are about 15 milliseconds accurate. The Timer on the other hand is completely software, so there is no accuracy, and it depends how fast your computer is. It's slow, sluggish, inaccurate, inconsistant, and gets worse the more you run simutaniously because the others need to fire off one by one before the next timer can fire.

    However, you can make the timeGetTime API be 1 ms accurate by setting both of these to 1:

    VB Code:
    1. Public Declare Function timeBeginPeriod Lib "winmm.dll" (ByVal uPeriod As Long) As Long
    2. Public Declare Function timeEndPeriod Lib "winmm.dll" (ByVal uPeriod As Long) As Long

    From this page:

    http://gpwiki.org/index.php/VB:Timers

  8. #8

    Thread Starter
    Member
    Join Date
    Nov 2006
    Posts
    51

    Re: Timers [Faster Time]

    How would i make this like a timer? Becuase im quite fimilar with the timers, as inaccurate as they can be...

    like for a timer i would go

    VB Code:
    1. Private Sub Timer1_Timer()
    2. 'Code
    3. End Sub

    What would i do to call the modules?

    Thanks
    ~Cody Woolaver

  9. #9
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Timers [Faster Time]

    Try this. Works like a timer only better.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function QueryPerformanceFrequency Lib "kernel32" (lpFrequency As Currency) As Long
    4. Private Declare Function QueryPerformanceCounter Lib "kernel32" (lpCount As Currency) As Long
    5.  
    6. Private Tick_Count As Currency
    7. Private Start_Time As Currency
    8. Private End_Time As Currency
    9. Private Delta_Time As Currency
    10.  
    11. Private Str As String
    12. Private Seconds As Long
    13.  
    14. Private Sub Form_Activate()
    15.  
    16.     AutoRedraw = True
    17.    
    18.     ScaleMode = 3
    19.    
    20.     QueryPerformanceFrequency Tick_Count
    21.    
    22.     QueryPerformanceCounter Start_Time
    23.    
    24.     Do
    25.    
    26.         DoEvents
    27.        
    28.         Cls
    29.        
    30.         Delta_Time = (End_Time - Start_Time) / Tick_Count
    31.        
    32.         Caption = Delta_Time
    33.        
    34.         'If Delta_Time >= 1 second then
    35.         'Add 1 to the Seconds and reset the clock
    36.        
    37.         If Delta_Time >= 1 Then
    38.        
    39.             'Timer code goes here
    40.             '--------------------------------
    41.  
    42.             Seconds = Seconds + 1
    43.  
    44.             '--------------------------------
    45.        
    46.             QueryPerformanceCounter Start_Time
    47.            
    48.         End If
    49.        
    50.         Str = "Time Elapsed: " & Seconds
    51.        
    52.         Print Str
    53.        
    54.         QueryPerformanceCounter End_Time
    55.                  
    56.     Loop
    57.  
    58. End Sub

  10. #10

    Thread Starter
    Member
    Join Date
    Nov 2006
    Posts
    51

    Re: Timers [Faster Time]

    so, since this way looks awesome... lol ( Thats a huge thanks ^^; )

    Can i finish my program, and then like email you the form, becasue i still dont know how im going to incorporate this in the way i would like to

    Thanks a ton!

  11. #11

    Thread Starter
    Member
    Join Date
    Nov 2006
    Posts
    51

    Re: Timers [Faster Time]

    Ok, ive been fooling around with your timer code, and i cannot quite seem to get it to work... Ive uploaded what i basically would like the speeds to be

    (There are minutes and hours, but i dont expect anyone to spend an hour watching a form -.-)

    I also dont know how to call this as a you would a timer... like for a timer you go

    VB Code:
    1. private sub timer1_timer()
    2. 'Your cude is processed for every interval
    3. end sub

    how am i going to do this for your code?

    VB Code:
    1. private sub seconds()
    2. msgbox "Look at me, im so annoying, i appear every second :D"
    3. end sub

    something like that maby?

    Thankyou
    ~Cody
    Attached Files Attached Files

  12. #12
    Addicted Member Jazz00006's Avatar
    Join Date
    Feb 2006
    Posts
    185

    Re: Timers [Faster Time]

    I'm probably wrong here, but

    VB Code:
    1. Private Declare Function QueryPerformanceFrequency Lib "kernel32" (lpFrequency As Currency) As Long
    2. Private Declare Function QueryPerformanceCounter Lib "kernel32" (lpCount As Currency) As Long
    3.  
    4. Private Tick_Count As Currency
    5. Private Start_Time As Currency
    6. Private End_Time As Currency
    7. Private Delta_Time As Currency
    8.  
    9. Private Str As String
    10. Private sub1, sub2, sub3, sub4, sub5, seconds, mins As Long
    11.  
    12. Private Sub Form_Activate()
    13.  
    14.     AutoRedraw = True
    15.    
    16.     ScaleMode = 3
    17.    
    18.     QueryPerformanceFrequency Tick_Count
    19.    
    20.     QueryPerformanceCounter Start_Time
    21.    
    22.     Do
    23.    
    24.         DoEvents
    25.        
    26.         Cls
    27.        
    28.         Delta_Time = (End_Time - Start_Time) / Tick_Count
    29.        
    30.         Caption = Delta_Time
    31.                
    32.         If Delta_Time >= 0.0001 Then
    33.         QueryPerformanceCounter Start_Time
    34.         sub5 = sub5 + 1
    35.     If sub5 = 10 Then
    36.         sub5 = 0
    37.         sub4 = sub4 + 1
    38.         End If
    39.     If sub4 = 10 Then
    40.         sub4 = 0
    41.         sub3 = sub3 + 1
    42.         End If
    43.     If sub3 = 10 Then
    44.         sub3 = 0
    45.         sub2 = sub2 + 1
    46.         End If
    47.     If sub2 = 10 Then
    48.         sub2 = 0
    49.         sub1 = sub1 + 1
    50.         End If
    51.     If sub1 = 10 Then
    52.         sub1 = 0
    53.         seconds = seconds + 1
    54.     End If
    55.     If seconds = 60 Then
    56.         seconds = 0
    57.         mins = mins + 1
    58.     End If
    59.        
    60.        
    61.         QueryPerformanceCounter Start_Time
    62.  
    63.         End If
    64.        
    65.            
    66.            
    67.        
    68.        
    69.         Str = "Time Elapsed: " & mins & seconds & sub1 & sub2 & sub3 & sub4 & sub5
    70.        
    71.         Print Str
    72.        
    73.         QueryPerformanceCounter End_Time
    74.                  
    75.     Loop
    76.  
    77. End Sub


    If i understand it correctly, you were reseting the time constantly so it couldn't add up the numbers for you

  13. #13
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Timers [Faster Time]

    And on top of that, the Cls function was making your labels crazy!

    Heres your solution. Your big problem is the fact that you were checking if they were equal to a certain time. Well you kinda forgot its time you were working with cause the numbers are gonna go higher than that. Mod operator to the rescue! Note that the Mod operator doesn't work with decimals, so I created one that does called Modulus:

    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function QueryPerformanceFrequency Lib "kernel32" (lpFrequency As Currency) As Long
    4. Private Declare Function QueryPerformanceCounter Lib "kernel32" (lpCount As Currency) As Long
    5.  
    6. Private Tick_Count As Currency
    7. Private Start_Time As Currency
    8. Private End_Time As Currency
    9. Private Delta_Time As Currency
    10.  
    11. Private Str As String
    12. Private Seconds As Long
    13.  
    14. Private Function Modulus(ByVal Value1 As Double, ByVal Value2 As Double) As Double
    15.  
    16.     'Similar to Value1 Mod Value2 only you can do bigger values
    17.     'than Mod in this function.
    18.  
    19.     Modulus = Value1 - (Int(Value1 / Value2) * Value2)
    20.  
    21. End Function
    22.  
    23. Private Sub Form_Activate()
    24.  
    25.     AutoRedraw = True
    26.    
    27.     ScaleMode = 3
    28.    
    29.     QueryPerformanceFrequency Tick_Count
    30.    
    31.     QueryPerformanceCounter Start_Time
    32.    
    33.     Dim Sec1 As Long, Sec10 As Long, Sec100 As Long
    34.     Dim Sec1000 As Long, Sec10000 As Long
    35.    
    36.     Do
    37.    
    38.         DoEvents
    39.        
    40.         Delta_Time = (End_Time - Start_Time) / Tick_Count
    41.        
    42.         If Modulus(Delta_Time, 1) Then Sec1 = Sec1 + 1
    43.         If Modulus(Delta_Time, 0.1) Then Sec10 = Sec10 + 1
    44.         If Modulus(Delta_Time, 0.01) Then Sec100 = Sec100 + 1
    45.         If Modulus(Delta_Time, 0.001) Then Sec1000 = Sec1000 + 1
    46.         If Modulus(Delta_Time, 0.0001) Then Sec10000 = Sec10000 + 1
    47.        
    48.         lblsecs.Caption = CStr(Sec1)
    49.         lbl10.Caption = CStr(Sec10)
    50.         lbl100.Caption = CStr(Sec100)
    51.         lbl1000.Caption = CStr(Sec1000)
    52.         lbl10000.Caption = CStr(Sec10000)
    53.        
    54.         QueryPerformanceCounter End_Time
    55.                  
    56.     Loop
    57.  
    58. End Sub
    59.  
    60. Private Sub Form_Unload(Cancel As Integer)
    61.  
    62.     Unload Me
    63.    
    64.     End
    65.  
    66. End Sub

  14. #14

    Thread Starter
    Member
    Join Date
    Nov 2006
    Posts
    51

    Re: Timers [Faster Time]

    All of the values go up at the same rate ^^;

    it looks almsot exactly like the old one you made me, but there are no decimals, and it dos not reset to zero

    Thanks
    ~Cody Woolaver

Posting Permissions

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



Click Here to Expand Forum to Full Width