Visual Basic delay timing question

dullard

Elite Member
May 21, 2001
25,690
4,209
126
I'm writing a program and have to use visual basic drivers. So I'm stuck with VB. This program needs to have delays in mulitples of 0.005 seconds, although I'd accept delays in multiples of 0.01 seconds if possible. To do this I tried a code like this:

TimeStart = Timer()
Do While Timer() < TimeStart + 0.005*n
Loop


where n will vary as the program progresses. Unfortunately, the program wasn't running as I expected. After a bit of searching I found that the Timer() function isn't accurate enough - it gives time in multiples of 0.03 seconds. If I added this code in the loop:

print Timer()-TimeStart

Then I'd get results like this:

0.00
0.03
0.06
0.09
0.12
0.15


Is there any better way to include delays? I'm not too experienced with visual basic.

I've tried to do this:

For i=1 to 100000*n
next


however it doesn't seem like the timing is consistant with each run.