OnEnd EndProgram() '..... Function EndProgram() 'Do Stuff Here! End Function
Simple, Da?
The program will end when the user wishes as normal, calling EndProgram() before ending.
You can now call EndProgram() however, which does the same thing without exiting! :)
(I'm going to assume this isn't what you meant though ;) )