Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Specifying millisecond delays "precisely" in pure VFP code

Status
Not open for further replies.

wcglorioso

Programmer
Jul 23, 2003
30
0
0
PH
Here are several functions I know which introduce time delays:

INKEY([nSeconds] [, cHideCursor])
nSeconds
= Specifies how many seconds INKEY( ) waits for a keystroke

WAIT [cMessageText] [TO VarName] [WINDOW [AT nRow, nColumn]] [NOWAIT][CLEAR | NOCLEAR] [TIMEOUT nSeconds]
TIMEOUT nSeconds
= Specifies the number of seconds that can elapse without input from the keyboard or the mouse before the WAIT is terminated
= specifies the number seconds (fractional seconds are permitted) that elapse

MESSAGEBOX(eMessageText [, cTitleBarText][, nDialogBoxType ][, nTimeout])
nTimeout
= Specifies the number of milliseconds Visual FoxPro displays cMessageText without input from the keyboard or the mouse before clearing cMessageText

Except INKEY(), all other functions has visible output trace on screen unless INKEY() is set to show the cursor by including S in its cHideCursor parameter.

The WAIT function is much better than MESSAGEBOX() function in specifying millisecond delays but both will not precisely introduce the required millisecond delay because the time delay may prematurely elapse upon key press or mouse click at some time (sois INKEY() function).

*** WAIT time delay version
LOCAL lnstart, tDelay
tDelay=500 && millisec delay
lnstart=SECONDS()
WAIT WINDOW 'Please Wait...' TIMEOUT 0.5
MESSAGEBOX(SECONDS()-lnstart)

*** MESSAGEBOX() time delay version
LOCAL lnstart, tDelay
tDelay=500
lnstart=SECONDS()
MESSAGEBOX('Please wait...',0,'Time Delay',tDelay)
MESSAGEBOX((SECONDS()-lnstart)*1000)


INKEY has a limit of specifying and integer value for its nSeconds parameter "as documented" (or as I understand the documentation) but it can it also permit fractional seconds like WAIT as it turned out with the following codes:

*** INKEY() time delay version
LOCAL lnstart, tDelay
tDelay=500 && millisec delay
lnstart=SECONDS()
=INKEY(tDelay/1000)
MESSAGEBOX(SECONDS()-lnstart)

However, I have below my version of a time delay which is as precise as that of the preceeeding codes but does not have a visual trace or affected by key press or mouse click.

*** SECONDS() time delay version
LOCAL lnstart, tDelay
tDelay=500
lnstart=SECONDS()
DO WHILE (SECONDS()-lnstart)*1000 < tDelay
ENDDO
MESSAGEBOX(SECONDS()-lnstart)

I hope this qualifies as a good enough tip :)
 
wcglorioso,

How about:

DECLARE Sleep IN Win32API INTEGER nMilliseconds
Sleep(500)

Andy

 
That's what I call &quot;accurate&quot;.
 
The reason I prefer the winapi Sleep() function over any pure VFP method is that the DO WHILE mechanisms tend to tie up alot of CPU time. Sleep() can be counted as just about pure VFP because it is a standard windows api that exists on all platforms.
 
I agree completely.
Its why I used &quot;precisely&quot; than &quot;accurately&quot;. (I assumed accurately is stronger verb than precisely)
Thanks for the information.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top