06-07-2023, 01:38 AM
(06-05-2023, 09:17 PM)SMcNeill Wrote:As I promised above, here's the same example as what I'd used before -- but it's based off a simple ON TIMER event:(06-05-2023, 09:09 PM)bplus Wrote: Looks allot like my demo
https://qb64phoenix.com/forum/showthread...1#pid16301
It is about the simplest way to implement _EXIT into a program. Great minds think alike.
I'll do one later to cover the ON TIMER version, but it's really not much different. I'd bang it out real fast now, except I have company otw anytime now and need to cut up some watermelon and cantaloupe for their kids to enjoy outside while the rest of us do our own things.
Code: (Select All)
_Title "_Exit Demo by Steve"
Dim Shared a As _Integer64
If _Exit Then System 'If you've clicked the exit button before we've did
' anything more than display a screen and a title,
' let's just give up and quit early and call it a day!
' The whole point to this early call to _EXIT is to disable the auto-exit and just
'to let our program know that we're going to manually be checking for it from now on.
MyTimer = FreeTimer 'Get a timer handle
On Timer(MyTimer, 0.2) Shutdown 'Set the frequency that they timer should repeat
Timer(MyTimer) On 'Turn that timer on
Do 'a main loop to do whatever we want
Cls
a = a + 1
Print "Whee! I'm ah counting! "; a
_Limit 100 'I'm going to count 100 counts per second.
Loop 'and I'm going to run forever and ever and ever and ever (as long as no one exits the program)
Sub Shutdown
If _Exit Then 'Check the exit condition when according to the timer interval
Print
Print "Oh nos! You have found my weakness and shut me down after I have ah only counted ta"; a
a$ = "This is the end of ah me!"
For i = 1 To Len(a$)
Print Mid$(a$, i, 1); "..";
_Delay .2
Next
_Delay 2
Beep
Print "And now I is ended!"
System
End If
End Sub