Results 1 to 3 of 3

Thread: about exiting the program correctly

  1. #1

    about exiting the program correctly

    i refer to the code here http://www.thinbasic.com/community/s...ll=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'

  2. #2
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Philippines
    Age
    48
    Posts
    1,218
    Blog Entries
    1
    Rep Power
    133
    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 <<
    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
    
    Last edited by ReneMiner; 17-02-2016 at 10:49.
    [TABLE="class: tblf1 tblf-fullwidth tblf-alternate"]
    [TR]
    [TD][COLOR=#b22222][B][SIZE=1]The limit is[/SIZE][/B][/COLOR][/TD]
    [TD="class: isRelinked"] [COLOR=#0000cd][B][SIZE=1]Imagination[/SIZE][/B][/COLOR][/TD]
    [/TR]
    [/TABLE]

  3. #3
    Thank you ReneMiner
    it is interesting the many ways we can do things in thinbasic
    best regards

Similar Threads

  1. Example: Section 4.3 (page 28), My First OGL Program (second program)
    By kryton9 in forum ThinBASIC programming in OpenGL/TBGL
    Replies: 2
    Last Post: 26-02-2010, 06:01
  2. Forum not working correctly
    By Michael Clease in forum General
    Replies: 5
    Last Post: 21-08-2009, 15:58
  3. Is thinBundle working correctly?
    By Michael Hartlef in forum General
    Replies: 3
    Last Post: 02-09-2007, 15:17

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •