Author Topic: SCREEN 0 and _PRINTSTRING  (Read 4572 times)

0 Members and 1 Guest are viewing this topic.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
SCREEN 0 and _PRINTSTRING
« on: November 10, 2018, 07:35:24 pm »
Hi Guys

please can tell me where I make a mistake to get this screen half up blue and half down black?

Code: QB64: [Select]
  1. COLOR , 1
  2. COLOR 14, 7
  3. interface
  4. COLOR , 1
  5.  
  6.  
  7. SUB interface
  8.     DIM col AS INTEGER
  9.     _PRINTSTRING (34, 6), "ÉÍÍÍÍÍÍÍÍÍÍÍ»"
  10.     FOR col = 1 TO 20 STEP 1
  11.         _PRINTSTRING (34, 6 + col), "º           º"
  12.     NEXT col
  13.     _PRINTSTRING (34, 6 + col), "ÈÍÍÍÍÍÍÍÍÍÍͼ"
  14.  
Thanks
Programming isn't difficult, only it's  consuming time and coffee

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: SCREEN 0 and _PRINTSTRING
« Reply #1 on: November 10, 2018, 07:41:04 pm »
Not that many rows in screen 0, this works because I cut 10:

Code: QB64: [Select]
  1. COLOR , 1
  2. COLOR 14, 7
  3. interface
  4. COLOR , 1
  5.  
  6.  
  7. SUB interface
  8.     DIM col AS INTEGER
  9.     _PRINTSTRING (24, 6), "ÉÍÍÍÍÍÍÍÍÍÍÍ»"
  10.     FOR col = 1 TO 10 STEP 1
  11.         _PRINTSTRING (24, 6 + col), "º           º"
  12.     NEXT col
  13.     _PRINTSTRING (24, 6 + col), "ÈÍÍÍÍÍÍÍÍÍÍͼ"
  14.  
  15.  
When print exceeds the amount of rows that fit the font is changed to smaller to try and fit the additional rows.
« Last Edit: November 10, 2018, 07:52:42 pm by bplus »

FellippeHeitor

  • Guest
Re: SCREEN 0 and _PRINTSTRING
« Reply #2 on: November 10, 2018, 07:49:12 pm »
With _PRINTSTRING the order of parameters is first column then row, opposite to LOCATE which has row first then column. That's likely your mistake.
« Last Edit: November 10, 2018, 08:07:56 pm by FellippeHeitor »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: SCREEN 0 and _PRINTSTRING
« Reply #3 on: November 10, 2018, 08:02:14 pm »
Yeah, where he says col, he means row because that is how he used it to draw the frame.

FellippeHeitor

  • Guest
Re: SCREEN 0 and _PRINTSTRING
« Reply #4 on: November 10, 2018, 08:21:42 pm »
Actually Tempodi already got the order of parameters right; it's the FOR...NEXT loop that's going beyond SCREEN 0 dimensions:

You could just make SCREEN 0 bigger. Either with WIDTH:

Code: QB64: [Select]
  1. WIDTH 80, 27 'this changes the default 25 rows to 27, so your box is displayed with no errors
  2. COLOR , 1
  3. COLOR 14, 7
  4. interface
  5. COLOR , 1
  6.  
  7. SUB interface
  8.     DIM col AS INTEGER
  9.     _PRINTSTRING (34, 6), "ÉÍÍÍÍÍÍÍÍÍÍÍ»"
  10.     FOR col = 1 TO 20 STEP 1
  11.         _PRINTSTRING (34, 6 + col), "º           º"
  12.     NEXT col
  13.     _PRINTSTRING (34, 6 + col), "ÈÍÍÍÍÍÍÍÍÍÍͼ"
  14.  

Or with _NEWIMAGE:
Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(80, 27, 0) 'this also changes the default 25 rows to 27, so your box is displayed with no errors
  2. COLOR , 1
  3. COLOR 14, 7
  4. interface
  5. COLOR , 1
  6.  
  7. SUB interface
  8.     DIM col AS INTEGER
  9.     _PRINTSTRING (34, 6), "ÉÍÍÍÍÍÍÍÍÍÍÍ»"
  10.     FOR col = 1 TO 20 STEP 1
  11.         _PRINTSTRING (34, 6 + col), "º           º"
  12.     NEXT col
  13.     _PRINTSTRING (34, 6 + col), "ÈÍÍÍÍÍÍÍÍÍÍͼ"
  14.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: SCREEN 0 and _PRINTSTRING
« Reply #5 on: November 10, 2018, 08:30:25 pm »
Yeah, that's why I cut 10 lines out of loop, too many rows for screen 0 and why part gets colored and part doesn't, might even be a bug??? (ie why didn't color hold?)

Here is a framer I just modified from his code:
Code: QB64: [Select]
  1. COLOR , 1
  2. COLOR 11, 2
  3. framed 10, 5, 60, 10
  4.  
  5.  
  6. SUB framed (x, y, w, h)
  7.     _PRINTSTRING (x, y), "É"
  8.     FOR i = 1 TO w
  9.         _PRINTSTRING (x + i, y), "Í"
  10.     NEXT
  11.     _PRINTSTRING (x + i, y), "»"
  12.     FOR i = 1 TO h
  13.         _PRINTSTRING (x, y + i), "º" + SPACE$(w) + "º"
  14.     NEXT
  15.     _PRINTSTRING (x, y + i), "È"
  16.     FOR j = 1 TO w
  17.         _PRINTSTRING (x + j, y + i), "Í"
  18.     NEXT
  19.     _PRINTSTRING (x + j, y + i), "¼"
  20.  

Of course you have to be mindful of the screen dimensions of screen 0 or what ever screen being used.
« Last Edit: November 10, 2018, 08:33:33 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: SCREEN 0 and _PRINTSTRING
« Reply #6 on: November 10, 2018, 10:02:52 pm »
Now I center messages in the frame:
Code: QB64: [Select]
  1. _TITLE "Frame message for QB64 B+ 2018-11-10"
  2.  
  3. s$ = "Hi TempodiBasic," + CHR$(10)
  4. s$ = s$ + CHR$(10) + "How are you tonight?"
  5. s$ = s$ + CHR$(10) + "I hope this message is not too long, I am working from modified code of my messageBox$ function."
  6. s$ = s$ + " Testing adding a line that takes this beyond box height."
  7.  
  8. WHILE _KEYDOWN(27) = 0
  9.     COLOR 7, 0
  10.     CLS
  11.     COLOR 11, 2
  12.     framed 10, 5, 20, 5
  13.     centerPrint 10, 5, 20, 5, s$
  14.     _DELAY 1
  15.     COLOR 14, 4
  16.     framed 25, 13, 40, 10
  17.     centerPrint 25, 13, 40, 10, s$
  18.     _DELAY 1
  19.     COLOR 7, 1
  20.     framed 1, 1, 60, 6
  21.     centerPrint 1, 1, 60, 6, s$
  22.     _DELAY 1
  23.  
  24. SUB framed (x, y, w, h)
  25.     _PRINTSTRING (x, y), "É"
  26.     FOR i = 1 TO w
  27.         _PRINTSTRING (x + i, y), "Í"
  28.     NEXT
  29.     _PRINTSTRING (x + i, y), "»"
  30.     FOR i = 1 TO h
  31.         _PRINTSTRING (x, y + i), "º" + SPACE$(w) + "º"
  32.     NEXT
  33.     _PRINTSTRING (x, y + i), "È"
  34.     FOR j = 1 TO w
  35.         _PRINTSTRING (x + j, y + i), "Í"
  36.     NEXT
  37.     _PRINTSTRING (x + j, y + i), "¼"
  38.  
  39. SUB centerPrint (x, y, w, h, m$)
  40.  
  41.     'setup t$() to store strings with ti as index, limit w chars per line max, b$ is for build
  42.     REDIM t$(0): ti = 0: limit = w: b$ = ""
  43.     FOR i = 1 TO LEN(m$)
  44.         c$ = MID$(m$, i, 1)
  45.         'are there any new line signals, CR, LF or both? take CRLF or LFCR as one break but dbl LF or CR means blank line
  46.         SELECT CASE c$
  47.             CASE CHR$(13) 'load line
  48.                 IF MID$(m$, i + 1, 1) = CHR$(10) THEN i = i + 1
  49.                 t$(ti) = b$: b$ = "": ti = ti + 1: REDIM _PRESERVE t$(ti)
  50.             CASE CHR$(10)
  51.                 IF MID$(m$, i + 1, 1) = CHR$(13) THEN i = i + 1
  52.                 t$(ti) = b$: b$ = "": ti = ti + 1: REDIM _PRESERVE t$(ti)
  53.             CASE ELSE
  54.                 IF c$ = CHR$(9) THEN c$ = SPACE$(4): add = 4 ELSE add = 1
  55.                 IF LEN(b$) + add > limit THEN
  56.                     tail$ = "": ff = 0
  57.                     FOR j = LEN(b$) TO 1 STEP -1 'backup until find a space, save the tail end for next line
  58.                         d$ = MID$(b$, j, 1)
  59.                         IF d$ = " " THEN
  60.                             t$(ti) = MID$(b$, 1, j - 1): b$ = tail$ + c$: ti = ti + 1: REDIM _PRESERVE t$(ti)
  61.                             ff = 1 'found space flag
  62.                             EXIT FOR
  63.                         ELSE
  64.                             tail$ = d$ + tail$ 'the tail grows!
  65.                         END IF
  66.                     NEXT
  67.                     IF ff = 0 THEN 'no break? OK
  68.                         t$(ti) = b$: b$ = c$: ti = ti + 1: REDIM _PRESERVE t$(ti)
  69.                     END IF
  70.                 ELSE
  71.                     b$ = b$ + c$ 'just keep building the line
  72.                 END IF
  73.         END SELECT
  74.     NEXT
  75.     t$(ti) = b$
  76.     IF ti > h - 1 THEN stopper = h - 1 ELSE stopper = ti
  77.     IF ti < h - 1 THEN starter = (h - 1 - ti) \ 2 ELSE starter = 0
  78.     FOR r = 0 TO stopper
  79.         col = x + (w - LEN(t$(r))) / 2 + 1
  80.         _PRINTSTRING (col, y + r + starter + 1), t$(r)
  81.     NEXT
  82.  
« Last Edit: November 10, 2018, 10:07:45 pm by bplus »

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: SCREEN 0 and _PRINTSTRING
« Reply #7 on: November 10, 2018, 10:36:38 pm »
@BPlus: Have you at least considered trying an online dating service?
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: SCREEN 0 and _PRINTSTRING
« Reply #8 on: November 11, 2018, 01:34:11 pm »
Hi friends
thanks to show me that the bug was in my mind!
Yes I have forgotten that SCREEN 0 is 80 columns for 25 rows if I don't set it otherwise.
 :-)
 Great, the only obstacle between the idea and its realization as a good software is my mind .
:-))
As consequence I mustn't think but coding to have success!
Well this last seems a zen sentence about programmers.
Programming isn't difficult, only it's  consuming time and coffee

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: SCREEN 0 and _PRINTSTRING
« Reply #9 on: November 11, 2018, 05:19:52 pm »
WIDTH 80, 25 is the default window for SCREEN 0.

If you want more width, but the same font size, use...

WIDTH 80, 42

Note the length parameter does not affect the font size.

One under interesting one is WIDTH 80, 50. This will cause the window to be the same size as WIDTH 80, 25, but the font size will be half size. These widths were all based on QB45 actions.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: SCREEN 0 and _PRINTSTRING
« Reply #10 on: November 11, 2018, 05:45:37 pm »
@Pete
you're right, yesterday night my memory doesn't remember me that notion which we learn as one of the first to know to use SCREEN 0, in Qbasic it is 80x25 by default!

@Bplus
hey but you don't like STRING$ statement and you prefer to use FOR NEXT loop
Code: QB64: [Select]
  1. SUB framed (x, y, w, h)
  2.     _PRINTSTRING (x, y), "É"
  3.     '    FOR i = 1 TO w
  4.     _PRINTSTRING (x + 1, y), STRING$(w, "Í")
  5.     '   NEXT
  6.     _PRINTSTRING (x + 1 + w, y), "»"
  7.     FOR i = 1 TO h
  8.         _PRINTSTRING (x, y + i), "º" + SPACE$(w) + "º"
  9.     NEXT
  10.     _PRINTSTRING (x, y + i), "È"
  11.     '    FOR j = 1 TO w
  12.     _PRINTSTRING (x + 1, y + i), STRING$(w, "Í")
  13.     '   NEXT
  14.     _PRINTSTRING (x + j, y + i), "¼"
  15.  

Fine example of message box in ASCII!
Programming isn't difficult, only it's  consuming time and coffee

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: SCREEN 0 and _PRINTSTRING
« Reply #11 on: November 11, 2018, 08:32:11 pm »
Yes STRING$ works great, here is code fixed for miss placed bottom right corner:
Code: QB64: [Select]
  1. SUB framed (x, y, w, h)
  2.     _PRINTSTRING (x, y), "É" + STRING$(w, "Í") + "»"
  3.     FOR i = 1 TO h
  4.         _PRINTSTRING (x, y + i), "º" + SPACE$(w) + "º"
  5.     NEXT
  6.     _PRINTSTRING (x, y + h + 1), "È" + STRING$(w, "Í") + "¼"
  7.  
  8.  

I have an idea for coding alignment of strings for centerPrint messages so that you have choice of left, right or center alignments.

EDIT: more efficiency dreamed up overnight.
« Last Edit: November 12, 2018, 07:44:46 am by bplus »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: SCREEN 0 and _PRINTSTRING
« Reply #12 on: November 12, 2018, 02:21:25 pm »
I have an idea for coding alignment of strings for centerPrint messages so that you have choice of left, right or center alignments.

Just use my little text frame library?  ;D
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: SCREEN 0 and _PRINTSTRING
« Reply #13 on: November 12, 2018, 04:08:48 pm »
Is your little text frame library less than one sub 58 lines long?  (Knowing you, it might be!)  ;)

Code: QB64: [Select]
  1. _TITLE "Frame message for QB64 B+ 2018-11-10"
  2. '2018-11-11 frame mod with STRING$
  3. '2018-11-12 more frame improvement, embed into centerPrint and setup for text alignment
  4.  
  5.  
  6. s$ = CHR$(1) + "Hi TempodiBasic," + CHR$(10)
  7. s$ = s$ + CHR$(10) + "How are you tonight?" + CHR$(10)
  8. s$ = s$ + CHR$(10) + CHR$(9) + "I hope this message is too long, to test fitting a very long line into a box. I am working from modified code of my messageBox$ function."
  9. s$ = s$ + " Testing adding a line that takes this beyond box height."
  10.  
  11. h$ = CHR$(3) + "November 12, 2018 " + CHR$(10) + CHR$(10)
  12. h$ = h$ + CHR$(2) + "Instructions for alignment with centerPrint sub:" + CHR$(10) + CHR$(10) + CHR$(1)
  13. h$ = h$ + CHR$(9) + "Use CHR$(1) for left alignments." + CHR$(10)
  14. h$ = h$ + CHR$(9) + "Use CHR$(2) for center alignments." + CHR$(10)
  15. h$ = h$ + CHR$(9) + "Use CHR$(3) for right alignments." + CHR$(10)
  16. h$ = h$ + CHR$(9) + "Use CHR$(9) to insert 4 spaces with left alignment." + CHR$(10)
  17. h$ = h$ + CHR$(9) + "Use CHR$(10) or CHR$(13) or one + other, to start new line." + CHR$(10)
  18. h$ = h$ + CHR$(9) + "Use Chr$(10) or CHR$(13) twice in row for blank line." + CHR$(10) + CHR$(10) + CHR$(3)
  19. h$ = h$ + "bplus "
  20.  
  21. 'WHILE _KEYDOWN(27) = 0
  22. COLOR 7, 0
  23. COLOR 11, 2
  24. 'framed 10, 5, 20, 5
  25. 'check full fill
  26. centerPrint 1, 17, 20, 5, "Test full fill right in here!"
  27. centerPrint 1, 17, 20, 5, "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
  28. COLOR 14, 4
  29. 'framed 25, 13, 40, 10
  30. centerPrint 25, 15, 40, 8, s$
  31. COLOR 7, 1
  32. 'framed 1, 1, 60, 10
  33. centerPrint 1, 1, 60, 13, h$
  34. 'WEND
  35.  
  36.  
  37. SUB framed (x, y, w, h)
  38.     _PRINTSTRING (x, y), "É" + STRING$(w, "Í") + "»"
  39.     FOR i = 1 TO h
  40.         _PRINTSTRING (x, y + i), "º" + SPACE$(w) + "º"
  41.     NEXT
  42.     _PRINTSTRING (x, y + h + 1), "È" + STRING$(w, "Í") + "¼"
  43.  
  44. SUB centerPrint (x, y, w, h, m$)
  45.     'embed framed into code, so only one call needed
  46.     _PRINTSTRING (x, y), "É" + STRING$(w, "Í") + "»"
  47.     FOR i = 1 TO h
  48.         _PRINTSTRING (x, y + i), "º" + SPACE$(w) + "º"
  49.     NEXT
  50.     _PRINTSTRING (x, y + h + 1), "È" + STRING$(w, "Í") + "¼"
  51.  
  52.     'setup t$() to store strings with ti as index, limit w chars per line max, b$ is for build
  53.     DIM t$(100), a(100) AS _BYTE: ti = 0: b$ = "": align = 2
  54.     FOR i = 1 TO LEN(m$)
  55.         c$ = MID$(m$, i, 1)
  56.         'are there any new line signals, CR, LF or both? take CRLF or LFCR as one break but dbl LF or CR means blank line
  57.         SELECT CASE c$
  58.             CASE CHR$(1): align = 1
  59.             CASE CHR$(2): align = 2
  60.             CASE CHR$(3): align = 3
  61.             CASE CHR$(13) 'load line
  62.                 IF MID$(m$, i + 1, 1) = CHR$(10) THEN i = i + 1
  63.                 t$(ti) = b$: b$ = "": a(ti) = align: ti = ti + 1
  64.             CASE CHR$(10)
  65.                 IF MID$(m$, i + 1, 1) = CHR$(13) THEN i = i + 1
  66.                 t$(ti) = b$: b$ = "": a(ti) = align: ti = ti + 1
  67.             CASE ELSE
  68.                 IF c$ = CHR$(9) THEN c$ = SPACE$(4): add = 4 ELSE add = 1
  69.                 IF LEN(b$) + add > w THEN
  70.                     tail$ = "": ff = 0
  71.                     FOR j = LEN(b$) TO 1 STEP -1 'backup until find a space, save the tail end for next line
  72.                         d$ = MID$(b$, j, 1)
  73.                         IF d$ = " " THEN
  74.                             t$(ti) = MID$(b$, 1, j - 1): b$ = tail$ + c$: a(ti) = align: ti = ti + 1
  75.                             ff = 1 'found space flag
  76.                             EXIT FOR
  77.                         ELSE
  78.                             tail$ = d$ + tail$ 'the tail grows!
  79.                         END IF
  80.                     NEXT
  81.                     IF ff = 0 THEN 'no break? OK
  82.                         t$(ti) = b$: b$ = c$: a(ti) = align: ti = ti + 1
  83.                     END IF
  84.                 ELSE
  85.                     b$ = b$ + c$ 'just keep building the line
  86.                 END IF
  87.         END SELECT
  88.     NEXT
  89.     t$(ti) = b$: a(ti) = align
  90.     IF ti > h - 1 THEN stopper = h - 1 ELSE stopper = ti
  91.     IF ti < h - 1 THEN starter = (h - 1 - ti) \ 2 ELSE starter = 0
  92.     FOR r = 0 TO stopper
  93.         IF a(r) = 1 THEN 'left
  94.             col = x + 1
  95.         ELSEIF a(r) = 2 THEN 'center
  96.             col = x + (w - LEN(t$(r))) / 2 + 1
  97.         ELSE ' right
  98.             col = x + w - LEN(t$(r)) + 1
  99.         END IF
  100.         _PRINTSTRING (col, y + r + starter + 1), t$(r)
  101.     NEXT
  102.  
  103.  
« Last Edit: November 12, 2018, 04:11:15 pm by bplus »