Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Timer Trap Problem
#7
(10-09-2024, 03:37 AM)eoredson Wrote: The actual code to trap Control-Break I am using is posted here:

Code: (Select All)

Rem ctrl-break sample v1.0a

' disable ctrl-break.
Print "Press Ctrl-Break to test:"
v = _Exit

' jump here to restart trap.
start:
Timer(t1) Off
t1 = _FreeTimer
Print "Timer handle"; t1
On Timer(t1, 1) GoSub trap
Timer(t1) On

' start inkey$ loop.
z = z + 1
Print "Timer start loop"; z
Do
  x$ = InKey$
  If Len(x$) Then
      If x$ = Chr$(27) Then End
  End If
Loop

' trap ctrl-break.
trap:
v = _Exit
y = y + 1
Print "Trap call"; y
If v Then
  x = x + 1
  Print "Break trap"; x
  Return start
End If
Return
    That seems like a lot of code for nothing.   Once _exit is called once then Ctrl/Break and "click the X" is trapped.   _exit returns the counts.    I just check _exit in an ON TIMER and set a flag variable.    I check that flag variable in my main program loop and set the behavior as if a User had selected my normal program Exit option.    Often that involves asking "Really want to Quit Y/N "     I think it's pretty important especially if you want your program to clean up any temporary files it might have created and/or return to the directory it started in if you may have changed directory's within the program.
Reply


Messages In This Thread
Timer Trap Problem - by eoredson - 10-09-2024, 01:30 AM
RE: Timer Trap Problem - by SMcNeill - 10-09-2024, 01:51 AM
RE: Timer Trap Problem - by eoredson - 10-09-2024, 02:28 AM
RE: Timer Trap Problem - by SMcNeill - 10-09-2024, 02:55 AM
RE: Timer Trap Problem - by eoredson - 10-09-2024, 03:02 AM
RE: Timer Trap Problem - by eoredson - 10-09-2024, 03:37 AM
RE: Timer Trap Problem - by ahenry3068 - 10-09-2024, 11:18 AM
RE: Timer Trap Problem - by Cobalt - 10-09-2024, 03:42 PM
RE: Timer Trap Problem - by bplus - 10-09-2024, 06:40 PM
RE: Timer Trap Problem - by eoredson - 10-10-2024, 12:24 AM



Users browsing this thread: 4 Guest(s)