Posts: 3
Threads: 1
Joined: Feb 2023
Reputation:
0
Hello everyone, I am using the QB64 for windows compatibility converted all the QB 4.5 to QB64 it has been working for 6 years now. Anyway one of my users asked me to disable the X on closing the program because they didn't want it to close in the middle of what they were doing so I put in the the command 'ex = _EXIT'. This works like it states you can't close the program with the X on the window. Now to kill the program when it freezes they have to kill the process in windows. Is there a why to use ON KEY to close it? I have tried ON KEY(1) with a subroutine and GOSUB it will not do the code when I press F1 so somehow the ON KEY is not working for me. I am using QB64 Version 1.1 Revision 20170120/51 does it work in more recent versions and where do I find them now. Alt + F4 should be what the Window close X button uses I think but maybe I am wrong.
Is there anyone that may know something to help me or should I leave it the way it is.
Posts: 4,707
Threads: 224
Joined: Apr 2022
Reputation:
322
02-08-2023, 07:28 PM
(This post was last modified: 02-08-2023, 07:43 PM by bplus.)
Hi
@Ron welcome to the forum!
This works for me on my Windows 10 laptop:
Code: (Select All)
_Title "Test F4 key to exit" 'b+ 2023-02-08 mod wiki On Key(n) example
Key(4) On ' F1 too important use F4 to quit
On Key(4) GoSub quit
Print "Press F4 to quit!"
temp = _Exit
Do
Cls
count = count + 1
Print count
_Limit 30 ' <<< really needed to slow down looping
Loop 'never ending loop
End ' just in case no fall through to gosub
quit: ' set to quit when press F4
End
Return
Never used On Key before, looks like you need additional Key(n) On as part of setup. And probably used to deactivate too, ie Key(n) Off
I tested on QB64pe 3.4.1 but see no reason why an earlier version would not work. I did have to slow the looping down with _Limit to catch the Key.
PS oh looky keys for the arrows!
724 855 599 923 575 468 400 206 147 564 878 823 652 556 bxor cross forever
Posts: 904
Threads: 38
Joined: Apr 2022
Reputation:
72
02-08-2023, 07:40 PM
(This post was last modified: 02-08-2023, 07:41 PM by SpriggsySpriggs.)
When you catch the _EXIT, you can check how they were trying to close it and then use SYSTEM to close. Looking at the
Wiki page on _EXIT, the function returns what method the user was using to attempt to close the program. If they pressed the X, you can just ignore it. If you wanted it to close on CTRL + BREAK, like in the example, you could then use SYSTEM when the return value matches.
The noticing will continue
Posts: 3
Threads: 1
Joined: Feb 2023
Reputation:
0
Thank You everyone I got it to recognize F4 and then I ask if they really want to exit and only accept y to exit
Yes an old program started in the 80s and I started on it in 2017 and brought it over to QB64. It is 100,000 lines of code but only am touching it when they need to add or change stored in the program variables I told them it is the wrong way to do it started to import from csv files but they don't change too often. So I maintain while building an order entry system for them in FULLSTACK which was also new for me. BASIC I USED way back in 1987 then never touched again until 2016.
Thanks Again all is working or will be working as I expect still testing it.
Ron.