Author Topic: Unexpected print output with TAB  (Read 2679 times)

0 Members and 1 Guest are viewing this topic.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Unexpected print output with TAB
« on: November 16, 2019, 03:09:03 pm »
Hi.
Please try this code. CHR$ is not printed 1x as expected, but first is printed CHR$(13) and then excepted CHR$. If in PRINT is not used TAB, this bug not occur. Used space in this code, TAB(2) is not enought space and _CONTROLCHR OFF disable some function in TAB, because if is _CONTROLCHR OFF deleted from code, is text printed as expected. (not to one row, but without CHR$(13)).

If is text insterted to string variable and then printed, is output correct.

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 256)
  2. FOR byte = 0 TO 255
  3.     PRINT byte; TAB(2); CHR$(byte); TAB(14); 'unexpected printing CHR$ (more than 1 print with TAB)
  4.     a$ = STR$(byte) + TAB(2) + CHR$(byte) + TAB(4) 'output as expected
  5.     'PRINT a$;
  6.     FOR rj = 7 TO 0 STEP -1
  7.         IF byte AND 2 ^ rj THEN Binar$ = Binar$ + "1" ELSE Binar$ = Binar$ + "0"
  8.     NEXT rj
  9.     PRINT Binar$
  10.     Binar$ = ""
  11.     SLEEP
  12.  

OR is this correct output, if _CONTROLCHR OFF show me text formating characters? 13 is enter, so as symbol for next row, which is not printed, because text formating is disabled???
« Last Edit: November 16, 2019, 03:13:31 pm by Petr »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Unexpected print output with TAB
« Reply #1 on: November 17, 2019, 02:50:29 pm »
I think there's a few things wrong here -- both in QB64 and with the code itself...

Code: [Select]
   PRINT byte; TAB(2); CHR$(byte); TAB(14); 'unexpected printing CHR$ (more than 1 print with TAB)

With the above, TAB tries to move us to an exact position on the current print line...   TAB(2) tries to move us over to the 2nd print position...  The problem here is that we've already PASSED that print position.   When we print byte, we print its value, as well as saving a spot for its sign, so we use 2 positions on the line to print to.... Our current print location would be back on the next line, directly below the byte, as illustrated with the code below:

Code: [Select]
SCREEN _NEWIMAGE(800, 600, 256)
'_CONTROLCHR OFF
FOR byte = 0 TO 9
    PRINT byte; TAB(2); CHR$(byte); TAB(14); 'unexpected printing CHR$ (more than 1 print with TAB)
    a$ = STR$(byte) + TAB(2) + CHR$(byte) + TAB(4) 'output as expected
    'PRINT a$;
    FOR rj = 7 TO 0 STEP -1
        IF byte AND 2 ^ rj THEN Binar$ = Binar$ + "1" ELSE Binar$ = Binar$ + "0"
    NEXT rj
    PRINT Binar$
    Binar$ = ""
    SLEEP
NEXT

Now, I don't think this would be the behaviour you're looking for with this particular set of code, so the code by itself is a little buggy...



With that said, however, it also seems as if QB64 is a little buggy in there somewhere.  With _CONSTROLCHR off, that TAB(2) isn't moving to the next line as it should, automatically.  Instead, it's printing the "new line" symbol on the screen as an ASCII character.  I'd definitely call it a bug in QB64, as I can't honestly think anybody would ever consider that to be the intended behavior of things. 

If you're at position 6 on a line, and then TAB(2), you should go to the 2nd print position of the next line for your print position -- NOT print a musical symbol onto the screen.

Odin should definitely move this into the bug section of the forums.  (At least, in my opinion, he should.)  If this isn't a bug, I'd love for someone to explain to me why it is the way it is.  I really can't fathom any reasonable explanation as to why someone would want it this way.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!