RE: On Exit question - TempodiBasic - 06-04-2023
Well
following the right thoughts of Steve I can affirm that I often (or always) do not use Option _explicit so that my code can be so bad and not working and I can abandon that project and flying on another flower and then another and another...
This is a superior coding tecniche to never end a project! It need many years to be learnt!
PS in the so long project that I have posted: Making Step by Step a sprite sheed editor in QB64 adding Option _explicit in those less 200 rows of code I find just 12 mistypos! LOL
We need not Option _Explicit.
RE: On Exit question - TempodiBasic - 06-04-2023
@NasaCow
on wikipage of _EXIT you find these instructions:
Quote: If a return value is not 0 the program can handle an exit request at a more convenient time if necessary.
After being read, the _EXIT value is reset to 0 so store the value when a program delays an exit request.
Note: Once _EXIT has been used once, you must monitor your program by checking it for user _EXIT requests.
Don't just use _EXIT once to prevent a user from exiting a program early, as that constitutes bad practice.
....
can you find another way to manage the issue about closing by brute force your program?
RE: On Exit question - TerryRitchie - 06-04-2023
(06-04-2023, 05:38 PM)TempodiBasic Wrote: @NasaCow
on wikipage of _EXIT you find these instructions:
Quote: If a return value is not 0 the program can handle an exit request at a more convenient time if necessary.
After being read, the _EXIT value is reset to 0 so store the value when a program delays an exit request.
Note: Once _EXIT has been used once, you must monitor your program by checking it for user _EXIT requests.
Don't just use _EXIT once to prevent a user from exiting a program early, as that constitutes bad practice.
....
can you find another way to manage the issue about closing by brute force your program?
I just include _EXIT in my checks for the user wanting to leave the program:
Foo = _EXIT
DO
.
. <code>
.
LOOP UNTIL _KEYDOWN(27) OR _EXIT ' ESC pressed or window X clicked
RE: On Exit question - TempodiBasic - 06-04-2023
Wow Terry
it is fantastic!
Sorry I do not write the wikipage of _EXIT.
Here a demo that stucks
buuuut I got only value 1 from _EXIT both by click on X of the window both pressing Alt+F4 (in windows 11 OS)
Code: (Select All) 'Disabling the default exit routinue
ExitFlag = _Exit
On Timer(1) GoSub ShutDown
Timer On
Print "Waiting _EXIT function"
While 1: Wend
End
ShutDown:
ExitFlag = _Exit
If ExitFlag Then Print ExitFlag 'System '<------- remming this we must build a manual exiting routine or the program stucks
Return
See Later
RE: On Exit question - NasaCow - 06-04-2023
(06-04-2023, 05:38 PM)TempodiBasic Wrote: @NasaCow
on wikipage of _EXIT you find these instructions:
Quote: If a return value is not 0 the program can handle an exit request at a more convenient time if necessary.
After being read, the _EXIT value is reset to 0 so store the value when a program delays an exit request.
Note: Once _EXIT has been used once, you must monitor your program by checking it for user _EXIT requests.
Don't just use _EXIT once to prevent a user from exiting a program early, as that constitutes bad practice.
....
can you find another way to manage the issue about closing by brute force your program? Well, that's what I am trying to figure out by copying the wiki example. I was just trying to get it to system out still without doing anything else but it also said you need to an initial _EXIT to enable the use.
(06-04-2023, 08:35 PM)TerryRitchie Wrote: (06-04-2023, 05:38 PM)TempodiBasic Wrote: @NasaCow
on wikipage of _EXIT you find these instructions:
Quote: If a return value is not 0 the program can handle an exit request at a more convenient time if necessary.
After being read, the _EXIT value is reset to 0 so store the value when a program delays an exit request.
Note: Once _EXIT has been used once, you must monitor your program by checking it for user _EXIT requests.
Don't just use _EXIT once to prevent a user from exiting a program early, as that constitutes bad practice.
....
can you find another way to manage the issue about closing by brute force your program?
I just include _EXIT in my checks for the user wanting to leave the program:
Foo = _EXIT
DO
.
. <code>
.
LOOP UNTIL _KEYDOWN(27) OR _EXIT ' ESC pressed or window X clicked This is actually a great idea, will force run all my normal saving routinues. Does _EXIT in this case retain it value so I can system out afterwards or should I set a flag to retain the value of _EXIT? (Pressing the 'X' multiple times to system out may annoy the user...)
RE: On Exit question - TerryRitchie - 06-05-2023
(06-04-2023, 11:59 PM)NasaCow Wrote: (06-04-2023, 05:38 PM)TempodiBasic Wrote: @NasaCow
on wikipage of _EXIT you find these instructions:
Quote: If a return value is not 0 the program can handle an exit request at a more convenient time if necessary.
After being read, the _EXIT value is reset to 0 so store the value when a program delays an exit request.
Note: Once _EXIT has been used once, you must monitor your program by checking it for user _EXIT requests.
Don't just use _EXIT once to prevent a user from exiting a program early, as that constitutes bad practice.
....
can you find another way to manage the issue about closing by brute force your program? Well, that's what I am trying to figure out by copying the wiki example. I was just trying to get it to system out still without doing anything else but it also said you need to an initial _EXIT to enable the use.
(06-04-2023, 08:35 PM)TerryRitchie Wrote: (06-04-2023, 05:38 PM)TempodiBasic Wrote: @NasaCow
on wikipage of _EXIT you find these instructions:
....
can you find another way to manage the issue about closing by brute force your program?
I just include _EXIT in my checks for the user wanting to leave the program:
Foo = _EXIT
DO
.
. <code>
.
LOOP UNTIL _KEYDOWN(27) OR _EXIT ' ESC pressed or window X clicked This is actually a great idea, will force run all my normal saving routinues. Does _EXIT in this case retain it value so I can system out afterwards or should I set a flag to retain the value of _EXIT? (Pressing the 'X' multiple times to system out may annoy the user...) I've never really checked for this. I've always made sure to include an _EXIT check in all my loops where I feel a user may want to leave. I would assume _EXIT contains a testable value only when the X close button is depressed on a window. It would be easy enough to do the following to be sure _EXIT is captured:
Foo = _EXIT
Leave = 0
DO
.
IF _EXIT THEN Leave = -1
.
. <more code>
.
LOOP UNTIL _KEYDOWN(27) OR Leave
You could:
DIM SHARED Leave AS INTEGER
somewhere at the top of your code. That way, if you enter another sub/function within the <more code> area that sub/function can set Leave appropriately as well and it will retain the value when sub/function exits. You could even have a check at the beginning of the other subs/functions:
IF Leave THEN EXIT SUB ' or EXIT FUNCTION
that would immediately exit a sub/function if Leave was already previously set. No need to continue further if the user is wanting to exit. Just a few thoughts.
RE: On Exit question - NasaCow - 06-05-2023
(06-05-2023, 12:31 AM)TerryRitchie Wrote: (06-04-2023, 11:59 PM)NasaCow Wrote: (06-04-2023, 05:38 PM)TempodiBasic Wrote: @NasaCow
on wikipage of _EXIT you find these instructions:
....
can you find another way to manage the issue about closing by brute force your program? Well, that's what I am trying to figure out by copying the wiki example. I was just trying to get it to system out still without doing anything else but it also said you need to an initial _EXIT to enable the use.
(06-04-2023, 08:35 PM)TerryRitchie Wrote: I just include _EXIT in my checks for the user wanting to leave the program:
Foo = _EXIT
DO
.
. <code>
.
LOOP UNTIL _KEYDOWN(27) OR _EXIT ' ESC pressed or window X clicked This is actually a great idea, will force run all my normal saving routinues. Does _EXIT in this case retain it value so I can system out afterwards or should I set a flag to retain the value of _EXIT? (Pressing the 'X' multiple times to system out may annoy the user...) I've never really checked for this. I've always made sure to include an _EXIT check in all my loops where I feel a user may want to leave. I would assume _EXIT contains a testable value only when the X close button is depressed on a window. It would be easy enough to do the following to be sure _EXIT is captured:
Foo = _EXIT
Leave = 0
DO
.
IF _EXIT THEN Leave = -1
.
. <more code>
.
LOOP UNTIL _KEYDOWN(27) OR Leave
You could:
DIM SHARED Leave AS INTEGER
somewhere at the top of your code. That way, if you enter another sub/function within the <more code> area that sub/function can set Leave appropriately as well and it will retain the value when sub/function exits. You could even have a check at the beginning of the other subs/functions:
IF Leave THEN EXIT SUB ' or EXIT FUNCTION
that would immediately exit a sub/function if Leave was already previously set. No need to continue further if the user is wanting to exit. Just a few thoughts.
I tested it real quick, it does clear out on the read on the loop so a flag is needed. Easily solved with a global ExitFlag that will system out when all work is properly saved. Should be pretty easy to bring into the program. Thanks for the back and forth, it is the best way for me to figure things out and the idea to use it with a loop-exiting mechanic!
Code: (Select All) $NOPREFIX
OPTION EXPLICIT
DIM AS INTEGER ExitFlag
ExitFlag = EXIT
DO
LIMIT 30
ExitFlag = EXIT
LOOP UNTIL ExitFlag
PRINT "Exit code from _EXIT:"; EXIT
PRINT "Exit code from ExitFlag:"; ExitFlag
SLEEP
SYSTEM
RE: On Exit question - SMcNeill - 06-05-2023
The easiest way to use _EXIT, is just like the following:
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.
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.
If _Exit Then Shutdown 'Here we check our exit flag and if it's called, we jump to the shutdown routine.
Loop 'and I'm going to run forever and ever and ever and ever (as long as no one exits the program)
Sub Shutdown
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 Sub
RE: On Exit question - bplus - 06-05-2023
Looks allot like my demo
https://qb64phoenix.com/forum/showthread.php?tid=1713&pid=16301#pid16301
RE: On Exit question - SMcNeill - 06-05-2023
(06-05-2023, 09:09 PM)bplus Wrote: Looks allot like my demo
https://qb64phoenix.com/forum/showthread.php?tid=1713&pid=16301#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.
|