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
    Germany
    Age
    54
    Posts
    1,534
    Rep Power
    171
    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.
    I think there are missing some Forum-sections as beta-testing and support

  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

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

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