Results 1 to 3 of 3

Thread: console-bug? swallows/casts chars?

  1. #1
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Philippines
    Age
    47
    Posts
    1,218
    Blog Entries
    1
    Rep Power
    133

    console-bug? print swallows chars?

    I was experimenting a little, playing around with heap and such and found some weird behaviour when using Print

    Not sure about the reason but if i use Print to print out single letters in a row
    (String * 1 here, but same happens if using Byte-layover and CHR$(variable) -function)
    somehow the first char does not seem to reach the console-window
    depending on how the string gets composed:

    "string" & {variable|function} [&...]
    or
    {variable|function} & "string" [&...]



    Uses "console"
    
    
    Dim foo As DWord = HEAP_AllocByStr( "hello world!" _
                                         & $CRLF _
                                         & "welcome to thinBasic" )
                                         
    
    PrintL HEAP_Get(foo)
    PrintL
    
    
    Dim char As String * 1 At foo
    
    PrintL "first char: " & $DQ & char & $DQ 
    PrintL
    
    PrintL "run 1: string " & $DQ & "." & $DQ & " in front"
    PrintL
    
    While VarPtr(char) <= HEAP_End(foo) 
    
     Print "." & char 
      
      SetAt( char, VarPtr(char)+1 ) 
    Wend
      
    PrintL Repeat$(2, $CRLF)
    
    
    ' reset
    SetAt(char, foo)
    PrintL "run 2: variable 'char' in front"
    PrintL
    
    While VarPtr(char) <= HEAP_End(foo) 
    
      Print char & "." 
      SetAt( char, VarPtr(char)+1 ) 
    Wend
    
    PrintL Repeat$(2, $CRLF)
    SetAt(char, foo)
    PrintL "where is the " & $DQ & char & $DQ & " ?"
    PrintL $CRLF & " -------------------- key to end"
    
    WaitKey
    
    Last edited by ReneMiner; 30-01-2015 at 13:01.
    [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]

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    50
    Posts
    8,187
    Blog Entries
    2
    Rep Power
    10
    no bug, just illusion

    If you debug and set a breakpoint just before the second loop ... going step by step you will see that the illusion occurs when you will reach CRLF.
    First line of the string will be printed correctly but when you will reach the CR, PRINT will do its job to "carriage return" the cursor at the beginning of the line.
    At that point you will print a "." that will go over the "h"

    Then you will Print a LF and at that point Print will set the cursor to the next line.

    So: illusion that the "h" has disappeared but in reality the "h" is just overwritten by a "." after CR return the cursor at the beginning of the line
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win10Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

  3. #3
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Philippines
    Age
    47
    Posts
    1,218
    Blog Entries
    1
    Rep Power
    133
    ok, so as long as it's only wrong display and not losing data - no big deal.
    I was just confused- often use console to debug/test results etc and it did not print out what i awaited.
    [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]

Similar Threads

  1. Console Box and Console Readline
    By TheOne in forum Console
    Replies: 8
    Last Post: 22-03-2011, 18:32
  2. Console Colors
    By danbaron in forum General purpose scripts
    Replies: 0
    Last Post: 30-01-2010, 08:21
  3. console simulation ui
    By Lionheart008 in forum UI (User Interface)
    Replies: 1
    Last Post: 09-01-2010, 11:23
  4. my first console script :)
    By Lionheart008 in forum Console
    Replies: 2
    Last Post: 18-02-2009, 13:14
  5. console scripts
    By sandyrepope in forum Console: source code examples for beginners
    Replies: 4
    Last Post: 16-02-2007, 02:11

Posting Permissions

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