How do you end an O2 program, if you're not in the main part of the code?
I looked in control_flow.md, but did not see anything. I'm sure I could have missed it.
Thanks!
Hello Ed,
please see Reply #5 for SUB ExitProgram in http://www.jose.it-berater.org/smfforum/index.php?topic=5272.0
use corewin
%PROCESS_TERMINATE= 0x0001
'=========================
' to terminate the program immediately
SUB ExitProgram
LOCAL hProc ,ProcId ,ExitAddress AS sys
Local lResult AS LONG
ProcId = GetCurrentProcessId
hProc = OpenProcess(BYVAL %PROCESS_TERMINATE, BYVAL 0, BYVAL ProcID)
IF hProc <> %NULL THEN
lresult = GetExitCodeProcess(hProc, ExitAddress)
IF lresult <> 0 THEN
CALL ExitProcess(ExitAddress)
ELSE
CloseHandle hProc
END IF
END IF
this terminates the program wherever or whenever it is called, it is a clean exit
whole that code for clean exit ?
wow
ok
i am using just ExitProcess(0)
and looks so far that work
Programs can be properly terminated with end in the global space. For instance:
gosub greet
end
greet:
print "Helo"
ret
Technically a better solution then with PB.
Where you need
SendMessage hWndForm, %WM_CLOSE, 0, 0
I prefer a simple "End" and the Compiler makes all the internal Cleanup.
Does it?
Yes, o2 does its internal global cleanup, before calling ExitProcess.
END is used together with other keywords to close loops or blocks.
By itself, in the global space, it is used to terminate the program.
As we can see from the Help page.
well i never use END ..
... actually there are many ways to end a program ...
Sometimes we also use the figure method.