@NasaCow
A timer is not needed nor desired! with _Exit checking.
I am pretty sure you have a main menu loop in your program so here is how to check if user pressed an exit sequence or the very common alternate, the escape key:
Of course you don't have to signal user the work is saved or you could use a message box. This is just roughed out way to use _Exit.
Notice at end, while sleeping the top right X box does not work because _Exit is still forcing a coded exit method, in this case any keypress after Sleep.
A timer is not needed nor desired! with _Exit checking.
I am pretty sure you have a main menu loop in your program so here is how to check if user pressed an exit sequence or the very common alternate, the escape key:
Code: (Select All)
Dim Shared As Long Saved ' variable that tracks work has been saved
' loadWork
' Saved = -1 ' you are saved right after you load the work data into arrays
' once exit has been called you can't use top right x to quit
' put checkQuitSave in Main loop of your program
Do ' run main menu of program here
' show menu
' catch user choice
' do it
' return to menu
Saved = 0 ' signal we made a change to work we want saved
' just to test code to see
i = i + 1
Print i
checkQuitSave
_Limit 30 ' slow down print numbers
Loop Until _KeyDown(27) ' escape
If Saved = 0 Then SaveWork ' because escape key does not run through checkQuitSave
Print "Goodbye zzz... press any to end" ' signal ending of program
Sleep
End
End
Sub SaveWork
' put everything you need to save users work here
Print "Work has been saved, zzz... press any to continue"
Sleep
Saved = -1 ' last line
End Sub
Sub checkQuitSave ' does the user wants to quit
If _Exit Then ' only when user is tryying to quit with top right click or Ctrl+break whatever break key is stops alt + F4 too
If Saved = 0 Then
SaveWork
Print "Goodbye zzz... press any to end" ' signal ending of program
Sleep
End
End If
End If
End Sub
Of course you don't have to signal user the work is saved or you could use a message box. This is just roughed out way to use _Exit.
Notice at end, while sleeping the top right X box does not work because _Exit is still forcing a coded exit method, in this case any keypress after Sleep.
b = b + ...