QB64 Phoenix Edition
On Exit question - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1)
+--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3)
+---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10)
+---- Thread: On Exit question (/showthread.php?tid=1713)

Pages: 1 2 3 4 5 6


RE: On Exit question - SMcNeill - 06-07-2023

(06-05-2023, 09:17 PM)SMcNeill Wrote:
(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.  Wink

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.  Smile
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:

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



RE: On Exit question - TempodiBasic - 06-07-2023

ON _EXIT GOSUB season's fruit


Season's fruit:
strawberry
cherry
peach
apricot
watermelon
cantaloupe
grape
RETURN


RE: On Exit question - TempodiBasic - 06-07-2023

Hi
a little question to you QB64 friends...
I am not able to find key BREAK on my notebook keyboard... (I only found Canc, Stamp, Ins, Esc)
Should you run my little demo on your PC/notebook to test the Ctrl+Break option?

Code: (Select All)
foo = _Exit
Print "Welcome to the _EXIT test code!"
Print "Please press X on the window bar or / and Alt+F4 on keyboard or Ctrl+Break on keyboard and look at results"
Print "press Spacebar to quit program"

View Print 5 To 20
While kb <> 32
    kb = _KeyHit
    _Delay 2
    food = _Exit
    On food GOSUB X, AltF4, CtrlBreak, XCtrlBreak
Wend
End

X:
Print "You have clicked on X of the window"
Return

AltF4:
Print "You have pressed Alt + F4 on keyboard"
Return

CtrlBreak:
Print " You have pressed Ctrl+ Break on keyboard"
Return

XCtrlBreak:
Print "You have pressed Ctrl+Break on keyboard and you have clicke on X of the window"
Return
Thanks

Moreover pressind Alt + F4 (Windows command to close the program) _EXIT retruns 1. Is It right?


[Image: immagine-2023-06-07-113118736.png]
Thanks for answers and testing.


RE: On Exit question - NasaCow - 06-08-2023

(06-07-2023, 09:31 AM)TempodiBasic Wrote: Hi
a little question to you QB64 friends...
I am not able to find key BREAK on my notebook keyboard... (I only found Canc, Stamp, Ins, Esc)
Should you run my little demo on your PC/notebook to test the Ctrl+Break option?

Code: (Select All)
foo = _Exit
Print "Welcome to the _EXIT test code!"
Print "Please press X on the window bar or / and Alt+F4 on keyboard or Ctrl+Break on keyboard and look at results"
Print "press Spacebar to quit program"

View Print 5 To 20
While kb <> 32
    kb = _KeyHit
    _Delay 2
    food = _Exit
    On food GOSUB X, AltF4, CtrlBreak, XCtrlBreak
Wend
End

X:
Print "You have clicked on X of the window"
Return

AltF4:
Print "You have pressed Alt + F4 on keyboard"
Return

CtrlBreak:
Print " You have pressed Ctrl+ Break on keyboard"
Return

XCtrlBreak:
Print "You have pressed Ctrl+Break on keyboard and you have clicke on X of the window"
Return
Thanks

Moreover pressind Alt + F4 (Windows command to close the program) _EXIT retruns 1. Is It right?


[Image: immagine-2023-06-07-113118736.png]
Thanks for answers and testing.
According to the wiki, alt-F4 should return 1. Break can be assigned different keypress depending on who built it. For Lenovo, which I use, it is Function-B to send a break command.


RE: On Exit question - TempodiBasic - 06-09-2023

Oh my God!
Also you with Lenovo ideapad?

Well you are saying Fn+B = Ctrl+Break?

Ok I must correct my democode
Code: (Select All)
foo = _Exit
Print "Welcome to the _EXIT test code!"
Print "Please press X on the window bar or / and Alt+F4 on keyboard or Ctrl+Break on keyboard and look at results"
Print "press Spacebar to quit program"

View Print 5 To 20
While kb <> 32
    kb = _KeyHit
    _Delay 2
    food = _Exit
    On food GOSUB X, CtrlBreak, XCtrlBreak ', AltF4
Wend
End

X:
Print "You have clicked on X of the window or pressed Alt+F4"
Return

'AltF4:
'Print "You have pressed Alt + F4 on keyboard"
'Return

CtrlBreak:
Print " You have pressed Ctrl+ Break on keyboard"
Return

XCtrlBreak:
Print "You have pressed Ctrl+Break on keyboard and you have clicke on X of the window"
Return
Now it works as expeted.


RE: On Exit question - mnrvovrfc - 06-09-2023

(06-07-2023, 09:31 AM)TempodiBasic Wrote: Hi
a little question to you QB64 friends...
I am not able to find key BREAK on my notebook keyboard... (I only found Canc, Stamp, Ins, Esc)
Should you run my little demo on your PC/notebook to test the Ctrl+Break option?

On H.P. laptops like mine the following works: [CTRL][Fn][SHIFT].

Doesn't matter which CTRL key, but the SHIFT key has to be the one for your right hand -- the larger of the two. Usually that is marked as "pause" on top-left corner of the key. [Fn][Right-SHIFT] does like [SHIFT][@] on the Radio Shack TRS-80/Tandy Color Computer LOL. Yes that computer had a key left all to the at-sign.

Those key combinations don't always work on Linux however.


RE: On Exit question - bplus - 06-10-2023

(06-09-2023, 09:31 PM)mnrvovrfc Wrote:
(06-07-2023, 09:31 AM)TempodiBasic Wrote: Hi
a little question to you QB64 friends...
I am not able to find key BREAK on my notebook keyboard... (I only found Canc, Stamp, Ins, Esc)
Should you run my little demo on your PC/notebook to test the Ctrl+Break option?

On H.P. laptops like mine the following works: [CTRL][Fn][SHIFT].

Doesn't matter which CTRL key, but the SHIFT key has to be the one for your right hand -- the larger of the two. Usually that is marked as "pause" on top-left corner of the key. [Fn][Right-SHIFT] does like [SHIFT][@] on the Radio Shack TRS-80/Tandy Color Computer LOL. Yes that computer had a key left all to the at-sign.

Those key combinations don't always work on Linux however.
My windows 10-64 HP has "pause" in upper left of right hand shift key.

I will try that with Ctrl + with TempodiBasic code:

OK ctrl+fn+pause does ID exit correctly BUT! TempodiBasic's program wouldn't let me go with spacebar.
Too long a _delay also.

So here is still another b+ mod to make things better Smile
Code: (Select All)

foo = _Exit
Print "Welcome to the _EXIT test code!"
Print "Please press X on the window bar or / and Alt+F4 on keyboard or Ctrl+Break on keyboard and look at results"
Print "press Spacebar to quit program"

View Print 5 To 20
While _KeyDown(32) = 0
    kb = _KeyHit
    '_delay 2
    food = _Exit
    On food GOSUB X, CtrlBreak, XCtrlBreak ', AltF4
    _Limit 30
Wend
Print "You have successfully exited main loop and quit, thanks to bplus mod!"
End

X:
Print "You have clicked on X of the window or pressed Alt+F4"
Return

'AltF4:
'Print "You have pressed Alt + F4 on keyboard"
'Return

CtrlBreak:
Print " You have pressed Ctrl+ Break on keyboard"
Return

XCtrlBreak:
Print "You have pressed Ctrl+Break on keyboard and you have clicke on X of the window"
Return



RE: On Exit question - TempodiBasic - 06-17-2023

@Bplus
on my Lenovo with your mod I never am able to get XCtrlBreak option.
_LIMIT 30 is too short on my notebook for performing the 2 actions: click on X and press Fn+B keys!

How modify framepersecond value to fit it to different CPU?


RE: On Exit question - GareBear - 06-17-2023

bplus, your "another b+ mod" works great with my Dell laptop. I used: / and ALT+F4 to exit.


RE: On Exit question - bplus - 06-17-2023

(06-17-2023, 12:18 AM)TempodiBasic Wrote: @Bplus
on my Lenovo with your mod I never am able to get XCtrlBreak option.
_LIMIT 30 is too short on my notebook for performing the 2 actions: click on X and press Fn+B keys!

How modify framepersecond value to fit it to different CPU?

Well we have quite a difference of 2 secs in your original code and 30 times a second in mine.

2 secs was much too slow a response time, in anyone's system I would imagine?

I imagine the _Limit number would fit any keypress response needed in the real application we are testing for here.

BTW how did you get from foo to food? were you hungry because you had spaghetti on your mind? Smile

Update: Oh hey! I tagged myself by quoting Tempodi's tag on me! LOL