You could just put a label at the end of the program (right before "End") and if one of the variables is "quit" it would go to the label.
So check() could be
Function check(var$)
If var$ = "quit" Or var$ = "Quit" Or var$ = ...etc... Then
Goto endofprogramlabel
EndIf