O2 program termination

Started by Ed Davis, July 19, 2022, 05:55:12 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Ed Davis

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!
  •  

Chris Chancellor

#1
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
  •  

Zlatko Vid

whole that code for clean exit ?
wow

ok
i am using just  ExitProcess(0)
and looks so far that work
  •  

Charles Pegge

Programs can be properly terminated with end in the global space. For instance:


gosub greet
end

greet:
print "Helo"
ret

Theo Gottwald

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?

Charles Pegge

Yes, o2 does its internal global cleanup, before calling ExitProcess.

Nicola

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.

Zlatko Vid

  •  

Nicola

... actually there are many ways to end a program ...
Sometimes we also use the figure method.