HomePage | Optical Illusions | War Stories | QBasic | Dads Navy Days | Bristol | Bristol, USA | Bristol, Canada | Terre Haute | Miscellany | Web Stuff | About Ray | Site Map | Site Search | Messages | Credits | Links | Web Rings
QBasic | Errors | 40lb Weight | Bits | Chance | Colours | Dates | Delays | File Dialog | Files | Input | Matching | Menus | Mouse | Numbers | SeqNo | SIRDS | Sorts | Text | Timer | DLoads
Delays - slowing or pausing a program
Sometimes you may want to slow or pause your program. There are four ways this can be done.
Use TIMER, this is a good method for pausing or slowing down a program to intervals of around a quarter of a second.
SLEEP, a method of pausing a program for a whole number of seconds. Useful when displaying "splash" screens.
Do nothing loops, loops that simply count to a number then exit. This is not generally a good programming practice, but is an option. When using this method the results vary from computer to computer, but it is easy to implement.
WAIT, a method of introducing a very small delay into a program. The &H3DA, 8 part waits for a screen refresh.
'Delay.bas Ray Thomas April 2002 'Program to demonstrate delays DIM Text AS STRING 'Text to print DIM Count AS INTEGER 'Loop counter DIM Start AS SINGLE 'Timer variable Text$ = "Ray wrote this" CLS PRINT PRINT "Example using a TIMER delay" PRINT TIMER ON FOR Count = 1 TO LEN(Text$) Start = TIMER PRINT MID$(Text$, Count, 1); DO LOOP UNTIL TIMER > Start + .3 NEXT Count TIMER OFF PRINT PRINT PRINT PRINT "Example using a SLEEP delay" PRINT FOR Count = 1 TO LEN(Text$) PRINT MID$(Text$, Count, 1); SLEEP 1 NEXT Count PRINT PRINT PRINT PRINT "Example using a delay loop" PRINT FOR Count = 1 TO LEN(Text$) Start = 0 PRINT MID$(Text$, Count, 1); DO Start = Start + 1 LOOP UNTIL Start = 100000 NEXT Count PRINT PRINT PRINT PRINT "Example using a WAIT delay" PRINT FOR Count = 1 TO LEN(Text$) PRINT MID$(Text$, Count, 1); WAIT &H3DA, 8 WAIT &H3DA, 8, 8 NEXT Count END
Pausing a program until the user presses a key, or a combination of keys, is covered in on my Inputs page.
The programs on this page, like all the programs written for this site, can be downloaded from the DLoads page.
QBasic | Errors | 40lb Weight | Bits | Chance | Colours | Dates | Delays | File Dialog | Files | Input | Matching | Menus | Mouse | Numbers | SeqNo | SIRDS | Sorts | Text | Timer | DLoads
HomePage | Optical Illusions | War Stories | QBasic | Dads Navy Days | Bristol | Bristol, USA | Bristol, Canada | Terre Haute | Miscellany | Web Stuff | About Ray | Site Map | Site Search | Messages | Credits | Links | Web Rings