PDA

View Full Version : console-bug? swallows/casts chars?



ReneMiner
30-01-2015, 12:16
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

ErosOlmi
30-01-2015, 15:49
no bug, just illusion :p

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 :D but in reality the "h" is just overwritten by a "." after CR return the cursor at the beginning of the line

ReneMiner
30-01-2015, 15:54
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.