It worksby (no login)
That loop was intentionally left empty since some people might have really slow computers. xD Besides, it makes it smaller, shorter, simpler. I like things to be simple when possible.
The timer sub waits until the beginning of a second, then starts looping until a whole second has passed. It counts how many times the empty loop has looped in that one second, then stores that number in a shared variable.
Whenever you call the SNOOZE sub, you give it a number in seconds. Unlike SLEEP, however, this number doesn't have to be an integer. The SNOOZE sub uses the stored integer to calculate how many times it would have to loop through an empty loop to expend the amount of time you specified.
You see, it's actually using the fact that TIME$ changes only once every second.
You could use it for milliseconds by assigning thousandths of second, but it's really designed to be decimals of seconds. By the way, SNOOZE 0 doesn't take any time at all, and I didn't make it so a key would exit the loop. It could probably be added, but what's the point? If you can't wait less than a second to interrupt the program, you have a serious problem with your patience.
|Response Title||Author and Date|
|* Ever hear of TIMER? You have the problem!||Clippy on Nov 19|
|Elaborate||on Nov 19|
|* NOPE, you apparently know TOO MUCH ALREADY!||Clippy on Nov 19|
|Attitude much?||on Nov 19|
|* Don't feel bad. I mistook YOU for a programmer, :-O||Clippy on Nov 19|
|It's an easy mistake to make.||on Nov 19|
|Don't mind Clippy...||Pete on Nov 19|
|I'm not here to push anybody out ;)||on Nov 19|
|OK, if you INSIST!||on Nov 20|
|IC||on Nov 20|
|SNOOZE does work...||on Nov 20|
|Don't mind Pete. He SELLS his code!||Clippy on Nov 20|
|I'm running Mac||on Nov 20|
|I think it should be pointed out that Minty's concept is valid...||on Nov 20|
|Bob, post the code that YOU are using. It doesn't work the way I have it!||Clippy on Nov 20|
|I just used Minty's code, except...||on Nov 20|
|Try this code Bob. I even get the right loop counts, but no delay.||Clippy on Nov 20|
|I assume you're running it in QB64...||on Nov 20|
|Alright, I added one line of code -- try this in QB64...||on Nov 20|
|It works BETTER in QB64 than Qbasic on my XP.||Clippy on Nov 20|
|*Yeah, in QB/DOSBox loops are slo-o-ow, which is why it "sort of" worked there.||on Nov 21|
|CPU Speed can be adjusted in DOSBox||on Nov 21|
|Well, I never heard of a TIMER that didn't reset at midnite either.||Clippy on Nov 21|
|DOSBox is weird that way...||on Nov 21|
|Well I have DOSBOX, but I'm not planning on making a habit of it.||Clippy on Nov 21|
|It resets to the actual time when I start DOSBox||on Nov 21|
|I like this guy!!!||Unseen Machine on Nov 28|