Quote from xchellx on August 30, 2019, 1:56 amAsking for exit can be tedious when you have to make a single subroutine and a check for every time you want to do it. There are also cases where you can't account for an exit.
I have made something that will always ask to exit no matter how you close the application (x button, right-click on the taskbar icon to click close, etc.).
This requires calling a subroutine instead ofExit "" ""
but even then, places where it shuts down where you don't call Exit cant be accounted for, now it can by avoiding exit in this case. Doing it this way lets you have a choice of exiting without asking if you want to do this somewhere in your code.Code (comments explain):
Shutdown: .Check if Neobook is closing the app (via Exit "" "") or by another source (such as X button) GoSub "CheckShutdown" Subroutines: :CheckShutdown .Is shutdown source NOT by Neobook? (Was Exit "" "" NOT called?) If "[ShutdownSource]" "<>" "NeoBook" .Ask if user wants to close the application GoSub "AskShutdown" Else .Do do actions before shutting down (or call a shutdown subroutine) Alert "Bye" "Thanks for using my program :) EndIf Return :AskShutdown .Show message box asking user if they want to exit the program MessageBox "Exit" "Are you sure you want to exit?" "Yes|No" "[OptionChosen]" .Check if the user choose "Yes", if so exit else dont close the program If "[OptionChosen]" "=" "1" .Close the program Exit "" "" Else .Prevent application from closing this time SetVar "[ShutdownStatus]" "False" EndIf Return Button1 - Left Click: .If we are gonna make an exit button, we instead call "AskShutdown" subroutine INSTEAD OF Exit "" "" GoSub "AskShutdown"
Asking for exit can be tedious when you have to make a single subroutine and a check for every time you want to do it. There are also cases where you can't account for an exit.
I have made something that will always ask to exit no matter how you close the application (x button, right-click on the taskbar icon to click close, etc.).
This requires calling a subroutine instead of Exit "" ""
but even then, places where it shuts down where you don't call Exit cant be accounted for, now it can by avoiding exit in this case. Doing it this way lets you have a choice of exiting without asking if you want to do this somewhere in your code.
Code (comments explain):
Shutdown: .Check if Neobook is closing the app (via Exit "" "") or by another source (such as X button) GoSub "CheckShutdown" Subroutines: :CheckShutdown .Is shutdown source NOT by Neobook? (Was Exit "" "" NOT called?) If "[ShutdownSource]" "<>" "NeoBook" .Ask if user wants to close the application GoSub "AskShutdown" Else .Do do actions before shutting down (or call a shutdown subroutine) Alert "Bye" "Thanks for using my program :) EndIf Return :AskShutdown .Show message box asking user if they want to exit the program MessageBox "Exit" "Are you sure you want to exit?" "Yes|No" "[OptionChosen]" .Check if the user choose "Yes", if so exit else dont close the program If "[OptionChosen]" "=" "1" .Close the program Exit "" "" Else .Prevent application from closing this time SetVar "[ShutdownStatus]" "False" EndIf Return Button1 - Left Click: .If we are gonna make an exit button, we instead call "AskShutdown" subroutine INSTEAD OF Exit "" "" GoSub "AskShutdown"