Author Topic: Formula to convert Print to _Printstring  (Read 2718 times)

0 Members and 1 Guest are viewing this topic.

Offline Dimster

  • Forum Resident
  • Posts: 500
    • View Profile
Formula to convert Print to _Printstring
« on: February 21, 2022, 11:38:14 am »
Hello All

I'm fumbling for a formula which accurately converts the location on the screen when I switch some of my prior code from Print to _Printstring. Actually, it's not so much what I'm actually printing to the screen it's more the conversion of the comma's... as in Print "Hello World","Are you ready for the day",,,"YES/NO".

So those comma's move the print zone by 14 characters, so to convert to say a new screen (1800,900,32), what I have been doing is dividing 1800/14 (or whatever the new screen column by 14). It's close but no cigar. I wind up continuously playing with column value...takes forever to recreate the Print screen to _Printstring. Am I missing something in my formula or is this rough calculation the best approach to the recreation of the old screens?

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Formula to convert Print to _Printstring
« Reply #1 on: February 21, 2022, 11:54:08 am »
If you are printing with default size 8x16 chars then
divide x pixels _Width by 8 for columns and y pixels _Height by 16
cols = _width\8
rows = _height\16
notice I use \ (integer division not / float division)

And remember first row or col start at 0 not 1 for _printstring.

Code: QB64: [Select]
  1. Screen _NewImage(800, 480, 32) ' Graphics Screen  800\8 = 100 cols  480\16 = 30 rows
  2. text$ = "Here is first liner test... zzz"
  3. row = 1: col = 1
  4. Locate row, col: Print text$
  5. RndRow = Int(Rnd * (28)) + 2: RndCol = Int(Rnd * 40) + 1: rndText$ = "Here is rnd col row test."
  6. Locate RndRow, RndCol: Print rndText$
  7. locate2PrintString8x16 row, col, text$
  8. locate2PrintString8x16 RndRow, RndCol, rndText$
  9.  
  10. ' convert Locate Row, Col " : Print text$ to printString version  ON GRAPHICS Screens not Console or Screen 0
  11. Sub locate2PrintString8x16 (Row, Col, text$)
  12.     _PrintString ((Col - 1) * 8, (Row - 1) * 16), text$
  13.  

Good luck with the commas Prints.
« Last Edit: February 21, 2022, 12:17:45 pm by bplus »

Offline Dimster

  • Forum Resident
  • Posts: 500
    • View Profile
Re: Formula to convert Print to _Printstring
« Reply #2 on: February 21, 2022, 02:26:28 pm »
Thanks - I didn't think that I needed the row, just the column because the comma was a column or lateral move, plus bplus, that division by integer I definitely overlooked. Thanks again.