Results 1 to 10 of 10

Thread: "Exit While" works, but "Exit Do" hangs up in TBGL loops

  1. #1
    Member dcromley's Avatar
    Join Date
    Apr 2009
    Location
    Wyoming, USA
    Age
    86
    Posts
    80
    Rep Power
    23

    "Exit While" works, but "Exit Do" hangs up in TBGL loops

    I want to advance to the next figure when I hit TAB. In this script, Loop1 using "Exit While" works, but Loop2 using "Exit Do" hangs up. (Windows 10 - Thinair 1.9.16.11)

    So run this script and hit TAB 3 times. It should show figures 1, 2, 3, and 4, but it hangs up after figure 3.

      Uses "TBGL" 
      Global hWnd As DWord, n, fignum As Long
    
    Sub TBMain()
      Local s1 As String = "ESC to quit; TAB to advance"
      hWnd = TBGL_CreateWindowEx(s1, 640, 480, 32, 
        %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX)    
      TBGL_ShowWindow 
      TBGL_UseVSync 1  
      Dim hFont As DWord = TBGL_FontHandle("Courier New", 12) 
      TBGL_BuildFont( hFont )   
      TBGL_UseLightSource(%GL_LIGHT0, %TRUE)
      TBGL_SetLightParameter(%GL_LIGHT0, %TBGL_LIGHT_POSITION, 15, 5, 15, 1)
      TBGL_ResetKeyState()           
      fignum = 1
      Loop1() ' shows fig 1 -- hitting TAB advances to the fig 2   
      Loop1() ' shows fig 2 -- hitting TAB advances to the fig 3  
      Loop2() ' shows fig 3 -- hitting TAB hangs up the program
      Loop2() ' never gets to here                                                   
    End Sub
    
    Sub Loop1() ' uses "While .. Wend" -- "Exit While" is OK   
      While TBGL_IsWindow(hWnd) 
        TBGL_ClearFrame 
        TBGL_Camera(1, 1, 5, 0, 0, 0)   
        TBGL_UseLighting(%FALSE)  
        n += 1
        TBGL_PrintFont("Figure " & fignum & " - " & n, -1, 1, 0)
        TBGL_UseLighting(%TRUE)       
        If fignum = 1 Then
          TBGL_Box(1, 1.4, 2) ' figure 1   
        Else
          TBGL_Box(2, 1.4, 1) ' figure 2   
        End If
        TBGL_DrawFrame 
        If TBGL_GetWindowKeyOnce(hWnd, %VK_TAB) Then Exit While
        If TBGL_GetWindowKeyOnce(hWnd, %VK_ESCAPE) Then Stop
      Wend
      fignum += 1                               
    End Sub
    
    Sub Loop2() ' uses "Do While .. Loop" -- "Exit Do" hangs up
      Do While TBGL_IsWindow(hWnd) 
        TBGL_ClearFrame 
        TBGL_Camera(1, 1, 5, 0, 0, 0)   
        TBGL_UseLighting(%FALSE)  
        n += 1
        TBGL_PrintFont("Figure " & fignum & " - " & n, -1, 1, 0)
        TBGL_UseLighting(%TRUE)       
        If fignum = 3 Then
          TBGL_Box(1, 1.4, 2) ' figure 3   
        Else
          TBGL_Box(2, 1.4, 1) ' figure 4   
        End If
        TBGL_DrawFrame 
        If TBGL_GetWindowKeyOnce(hWnd, %VK_TAB) Then Exit Do
        If TBGL_GetWindowKeyOnce(hWnd, %VK_ESCAPE) Then Stop
      Loop           
      fignum += 1        
      MsgBox 0, "!!" ' never gets here
    End Sub
    

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    Can you please install thinBasic 1.9.16.16 and see if problem is still there?

    Especially in version 1.9.16.11 there were some serious bugs: http://www.thinbasic.com/community/showthread.php?12600

    Let me know.
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  3. #3
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Hi,

    tried it with thinBASIC 1.9.16.16 and no problems observed.


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  4. #4
    Member dcromley's Avatar
    Join Date
    Apr 2009
    Location
    Wyoming, USA
    Age
    86
    Posts
    80
    Rep Power
    23
    Yes, the latest thinBasic works. As usual, thank you for your speedy response.

  5. #5
    Member dcromley's Avatar
    Join Date
    Apr 2009
    Location
    Wyoming, USA
    Age
    86
    Posts
    80
    Rep Power
    23

    Same script, new thing

    I find that running the script and getting to figure 3, that the "close icon" (the "X") doesn't work. Do you find that?

  6. #6
    Hi dcromley
    yes the 'X' hangs on the 3rd run BUT: (my opinion only):
    there is a possibility that using :
    While TBGL_IsWindow(hWnd), or
    Do While TBGL_IsWindow(hWnd)
    instead of usual loops several times are dangerous, this like riding a helicopter to visit your neighbor 20 meters away. this is just a guess and not a scientific proof , depends on knowing that TBGL_IsWindow(hWnd) is a big thing and not a usual loop.

    instead i will use a less important loop:
    While TBGL_GetWindowKeyOnce(hWnd, %VK_TAB) = %FALSE
    and seems it runs okay with your program:
    Uses "TBGL"
    Global hWnd As DWord, n, fignum As Long
    
    Sub TBMain()
    Local s1 As String = "ESC to quit; TAB to advance"
    hWnd = TBGL_CreateWindowEx(s1, 640, 480, 32, 
    %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX) 
    TBGL_ShowWindow
    TBGL_UseVSync 1 
    Dim hFont As DWord = TBGL_FontHandle("Courier New", 12) 
    TBGL_BuildFont( hFont ) 
    TBGL_UseLightSource(%GL_LIGHT0, %TRUE)
    TBGL_SetLightParameter(%GL_LIGHT0, %TBGL_LIGHT_POSITION, 15, 5, 15, 1)
    TBGL_ResetKeyState() 
    fignum = 1
    Loop1() ' shows fig 1 -- hitting TAB advances to the fig 2 
    Loop1() ' shows fig 2 -- hitting TAB advances to the fig 3 
    Loop2() ' shows fig 3 -- hitting TAB hangs up the program 
    Loop2() ' never gets to here 
    
    End Sub
    
    Sub Loop1() ' uses "While .. Wend" -- "Exit While" is OK 
    While TBGL_GetWindowKeyOnce(hWnd, %VK_TAB) = %FALSE
    'While TBGL_IsWindow(hWnd) 
    TBGL_ClearFrame
    TBGL_Camera(1, 1, 5, 0, 0, 0) 
    TBGL_UseLighting(%FALSE) 
    n += 1
    TBGL_PrintFont("Figure " & fignum & " - " & n, -1, 1, 0)
    TBGL_UseLighting(%TRUE) 
    If fignum = 1 Then
    TBGL_Box(1, 1.4, 2) ' figure 1 
    Else
    TBGL_Box(2, 1.4, 1) ' figure 2 
    End If
    TBGL_DrawFrame
    'If TBGL_GetWindowKeyOnce(hWnd, %VK_TAB) Then Exit While
    If TBGL_GetWindowKeyOnce(hWnd, %VK_ESCAPE) Then Stop
    Wend
    fignum += 1
    
    End Sub
    
    Sub Loop2() ' uses "Do While .. Loop" -- "Exit Do" hangs up
    'While TBGL_IsWindow(hWnd) 'Do While TBGL_IsWindow(hWnd)
    While TBGL_GetWindowKeyOnce(hWnd, %VK_TAB) = %FALSE 
    TBGL_ClearFrame
    TBGL_Camera(1, 1, 5, 0, 0, 0) 
    TBGL_UseLighting(%FALSE) 
    n += 1
    TBGL_PrintFont("Figure " & fignum & " - " & n, -1, 1, 0)
    TBGL_UseLighting(%TRUE) 
    If fignum = 3 Then
    TBGL_Box(1, 1.4, 2) ' figure 3 
    Else
    TBGL_Box(2, 1.4, 1) ' figure 4 
    End If
    TBGL_DrawFrame
    'If TBGL_GetWindowKeyOnce(hWnd, %VK_TAB) Then Exit Do
    If TBGL_GetWindowKeyOnce(hWnd, %VK_ESCAPE) Then Stop
    Wend 'Loop
    fignum += 1
    
      
    MsgBox 0, "!!" ' never gets here
    End Sub
    
    Last edited by primo; 11-03-2016 at 15:09.

  7. #7
    Member dcromley's Avatar
    Join Date
    Apr 2009
    Location
    Wyoming, USA
    Age
    86
    Posts
    80
    Rep Power
    23

    A third issue

    Primo,

    Thanks for your thoughtful post. This script is your last post with Loop1 removed. The only reason I had 2 loops was to demonstrate the difference between "While .. Wend" and "Do While .. Loop". This script is smaller.

    BUT: when I run your (or this) script and hit the "Close" icon, I get the dangling "Background Process" titled "thinBasic Programming Language" running, and I have to end it using Task Manager. Do you have this issue?

    This issue (a [inadvertent] dangling process left without any window(s)) has been brought up in other threads.

      Uses "TBGL"
      Global hWnd As DWord, n, fignum As Long
     
    Sub TBMain()
      Local s1 As String = "ESC to quit; TAB to advance"
      hWnd = TBGL_CreateWindowEx(s1, 640, 480, 32, 
      %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX) 
      TBGL_ShowWindow
      TBGL_UseVSync 1 
      Dim hFont As DWord = TBGL_FontHandle("Courier New", 12) 
      TBGL_BuildFont( hFont ) 
      TBGL_UseLightSource(%GL_LIGHT0, %TRUE)
      TBGL_SetLightParameter(%GL_LIGHT0, %TBGL_LIGHT_POSITION, 15, 5, 15, 1)
      TBGL_ResetKeyState() 
      fignum = 3
      Loop2() ' shows fig 3 
      Loop2() ' shows fig 4
    End Sub
     
    Sub Loop2()
      'While TBGL_IsWindow(hWnd) 'Do While TBGL_IsWindow(hWnd)
      While TBGL_GetWindowKeyOnce(hWnd, %VK_TAB) = %FALSE
        TBGL_ClearFrame
        TBGL_Camera(1, 1, 5, 0, 0, 0) 
        TBGL_UseLighting(%FALSE) 
        n += 1
        TBGL_PrintFont("Figure " & fignum & " - " & n, -1, 1, 0)
        TBGL_UseLighting(%TRUE) 
        If fignum = 3 Then
          TBGL_Box(1, 1.4, 2) ' figure 3 
        Else
          TBGL_Box(2, 1.4, 1) ' figure 4 
        End If
        TBGL_DrawFrame
        'If TBGL_GetWindowKeyOnce(hWnd, %VK_TAB) Then Exit Do
        If TBGL_GetWindowKeyOnce(hWnd, %VK_ESCAPE) Then Stop
      Wend 'Loop
      fignum += 1
    End Sub
    
    Last edited by dcromley; 11-03-2016 at 19:29. Reason: added "inadvertent"

  8. #8
    dcromley,
    this will make it exit without thinbasic.exe stay in memory, so change line 36 like this:
    If TBGL_GetWindowKeyOnce(hWnd, %VK_ESCAPE) Or Not TBGL_IsWindow(hWnd) Then Stop
    
    this is tested in windows xp/32

    what is the name of the toy in your Avatar ? is it a gyroscope ? i have uploaded its image to images.google.com but it show only the avatar in thinbasic
    Last edited by primo; 11-03-2016 at 21:54.

  9. #9
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Hi friends,

    the TBGL_IsWindow is actually just a wrapper for https://msdn.microsoft.com/en-us/lib...=vs.85%29.aspx from Win32.
    It is not as helicopterish, as it might look, and it is safe to use.


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  10. #10
    Member dcromley's Avatar
    Join Date
    Apr 2009
    Location
    Wyoming, USA
    Age
    86
    Posts
    80
    Rep Power
    23
    Thanks guys.

    My avatar comes from a TBGL program I wrote 4+ years ago.
    The link to the thread is GimbalRock
    and the link to the zip package is GimbalRockZip

Similar Threads

  1. questions "shoot example" (tbgl)
    By Lionheart008 in forum TBGL module by Petr Schreiber
    Replies: 4
    Last Post: 16-06-2012, 11:20
  2. Forum: added "Auto Youtube Link-Converter" plugin
    By ErosOlmi in forum Web and Forum
    Replies: 0
    Last Post: 07-05-2011, 12:47
  3. Replies: 17
    Last Post: 21-02-2010, 07:45
  4. Uses "File", "Crypto" ... ???
    By marcuslee in forum thinBasic General
    Replies: 3
    Last Post: 01-12-2009, 19:38

Members who have read this thread: 1

Posting Permissions

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