Results 1 to 3 of 3

Thread: console-bug? swallows/casts chars?

  1. #1
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,529
    Rep Power
    170

    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.
    I think there are missing some Forum-sections as beta-testing and support

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    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/ | 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
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,529
    Rep Power
    170
    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.
    I think there are missing some Forum-sections as beta-testing and support

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

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
  •