PDA

View Full Version : about exiting the program correctly



primo
17-02-2016, 08:38
i refer to the code here http://www.thinbasic.com/community/showthread.php?12390-Tree-Recursion&p=90956&viewfull=1#post90956
which have this code

Randomize
Do
depth = Rnd(8, 10)
Canvas_Clear &HFFFFFF
MainDraw(300, 460, -90, depth)
Canvas_Redraw
Loop While Asc(Canvas_WaitKey) <> 27
it exits okay when we press ESC, but not when we click close button 'X', the thinbasic.exe stay in memory. so if want to keep that Do...Loop how to maneuver to catch the 'X' and exit the program completely
i have tried:
Loop While Asc(Canvas_WaitKey) <> 27 Or IsWindow(hwnd)=TRUE
but still can't exit completely when we click 'X'

ReneMiner
17-02-2016, 09:53
Loop While Asc(Canvas_WaitKey) <> 27 Or IsWindow(hwnd) = True

means
loop while either esc is not pressed or while the window exists

you would have to do both to exit:
close the window and then press esc to meet the exit-condition.


Suggest, try one of these:


' 1.
Do
'...
If Not IsWIndow(hWnd) Then Exit Do
Loop While Asc(Canvas_WaitKey) <> 27

'2.
Do
'...
Loop While All( Asc(Canvas_WaitKey) <> 27, IsWindow(hwnd) )



If you use tB-version 1.9.16.16 there may possibly be some
>> bug in Do-Loop While-Syntax << (http://www.thinbasic.com/community/showthread.php?12600-thinBASIC-1-9-16-X&p=92688#post92688)
i would prefer another syntax currently:




'3.
Do
'...
Loop Until Asc(Canvas_WaitKey) = 27 Or IsWindow(hwnd) = False

'4.
Do While IsWIndow(hWnd)
'...
Loop Until Asc(Canvas_WaitKey) = 27

'5. you could as well use While-Wend:
While IsWIndow(hWnd)
'...
If Asc(Canvas_WaitKey) = 27 Then Exit While
Wend

'6.
While All( Asc(Canvas_WaitKey) <> 27, IsWindow(hwnd) )
'...
Wend

'7. or use Repeat-Until:
Repeat
'... be aware there's no "Exit Repeat"
Until Asc(Canvas_WaitKey) = 27 Or IsWindow(hwnd) = False

primo
17-02-2016, 10:51
Thank you ReneMiner
it is interesting the many ways we can do things in thinbasic
best regards