QB64.com

QB64 is a modern extended BASIC programming language that retains QBasic/QuickBASIC 4.5 compatibility and compiles native binaries for Windows, Linux, and macOS.

The _PRINTSTRING statement prints text STRING using graphic column and row coordinate positions.

Syntax

_PRINTSTRING(column, row), textExpression$[, imageHandle&]

Parameter(s)

Description

Availability

Example(s)

Printing those unprintable ASCII control characters is no longer a problem.


SCREEN _NEWIMAGE(800, 600, 256)

FOR code = 0 TO 31
  chrstr$ = chrstr$ + CHR$(code) + SPACE$(1)
NEXT

_FONT _LOADFONT("C:\Windows\Fonts\Cour.ttf", 20, "MONOSPACE") 'select monospace font

_PRINTSTRING (0, 16), chrstr$

END 


  ☺ ☻ ♥ ♦ ♣ ♠ • ◘ ○ ◙ ♂ ♀ ♪ ♫ ☼ ► ◄ ↕ ‼ ¶ § ▬ ↨ ↑ ↓ → ← ∟ ↔ ▲ ▼

Making any QB64 program window larger using a SUB that easily converts PRINT to _PRINTSTRING.


Scr13& = _NEWIMAGE(320, 200, 13)  'this is the old SCREEN 13 image page to set the image
Big13& = _NEWIMAGE(640, 480, 256) 'use 4 X 3 aspect ratio that QBasic used when full screen

SCREEN Big13&
_DEST Scr13&
image1& = _LOADIMAGE("Howie.BMP", 256)
image2& = _LOADIMAGE("Howie2.BMP", 256)
_PUTIMAGE (10, 20), image1&, Scr13&
_PUTIMAGE (160, 20), image2&, Scr13&
_COPYPALETTE image1&, Scr13&
COLOR 151: LOCATE 2, 4: PRINTS "Screen 13 Height Reduction to 83%" 
LOCATE 22, 22: PRINTS CHR$(24) + " 4 X 3 Proportion"  'use concatenation
LOCATE 24, 21: PRINTS CHR$(27) + " Stretched at 100%" 'instead of a semicolon!
_COPYPALETTE Scr13&, Big13&  'required when imported image colors are used
_PUTIMAGE , Scr13&, Big13&   'stretches the screen to double the size
K$ = INPUT$(1)
END

SUB PRINTS (Text$)
row% = (CSRLIN - 1) * _FONTHEIGHT      'finds current screen page text or font row height
col% = (POS(0) - 1) * _PRINTWIDTH("W") 'finds current page text or font column width
_PRINTSTRING (col%, row%), Text$
END SUB 

Explanation: The procedure above creates a larger version of a SCREEN 13 window by stretching it with _PUTIMAGE. It cannot stretch PRINTed text so _PRINTSTRING must be used instead. LOCATE sets the PRINT cursor position for CSRLIN and POS(0) to read. The SUB then converts the coordinates to graphical ones. Then change PRINT to PRINTS using the IDE Search Menu. Download of Example 2 Bitmap images

Rotating a text string around a graphic object.


SCREEN 12 
DIM row AS INTEGER, cnt AS INTEGER, cstart AS SINGLE, cend AS SINGLE
DIM xrot AS INTEGER, yrot AS INTEGER, scale AS INTEGER
' _FULLSCREEN                       'full screen optional
cstart = 0: cend = 8 * ATN(1)
xrot = 6: yrot = 60: scale = 4 
row = 1
CIRCLE (320, 240), 15, 9: PAINT STEP(0, 0), 9
DO
  FOR i = cstart TO cend STEP .04
    x = 300 + (scale * 40 - (row * xrot)) * COS(i)
    y = 200 + (scale * 40 - (row * yrot)) * SIN(i)
    cnt = cnt + 1
    COLOR 7: _PRINTSTRING (x, y), "HELLO WORLD!", 0  'display 
    IF cnt = LEN(text$) * 8 THEN cnt = 0: EXIT DO
    _DISPLAY
    COLOR 0: _PRINTSTRING (x, y), "HELLO WORLD!", 0  'erase 
    _DELAY 0.02    
  NEXT
LOOP UNTIL INKEY$ = CHR$(27) 'escape key exit
COLOR 15 
END 

See Also