{{QBDLDATE:07-31-2022}} {{QBDLTIME:23:39:23}} {{DISPLAYTITLE:_PRINTSTRING}} The [[_PRINTSTRING]] statement prints text [[STRING|strings]] using graphic column and row coordinate positions. {{PageSyntax}} : [[_PRINTSTRING]]({{Parameter|column}}, {{Parameter|row}}), {{Parameter|textExpression$}}[, {{Parameter|imageHandle&}}] {{Parameters}} * {{Parameter|column}} and {{Parameter|row}} are [[INTEGER]] or [[LONG]] starting PIXEL (graphic) column and row coordinates to set text or custom fonts. * {{Parameter|textExpression$}} is any literal or variable [[STRING|string]] value of text to be displayed. * {{Parameter|imageHandle&}} is the optional image or destination to use. Zero designates current [[SCREEN (statement)|SCREEN]] page. {{PageDescription}} * The starting coordinate sets the top left corner of the text to be printed. Use [[_FONTHEIGHT]] to calculate that text or [[_FONT|font]] position * The [[_FONT]] size can affect the [[SCREEN (statement)|screen]] and row heights. ** Custom fonts are not required. [[_PRINTSTRING]] can print all [[ASCII]] characters. * [[_PRINTWIDTH]] can be used to determine how wide a text print will be so that the screen width is not exceeded. * If the {{Parameter|imageHandle&}} is omitted, the current image, page or screen destination is used. * Can use the current font alpha blending with a designated image background. See the [[_RGBA]] function example. * Use the [[_PRINTMODE]] statement before printing to set how the background is rendered. ** Use the [[_PRINTMODE (function)]] to find the current _PRINTMODE setting. * In SCREEN 0 (text only), [[_PRINTSTRING]] works as one-line replacement for '''LOCATE x, y: PRINT text$''', without changing the current cursor position. ==Availability== * In versions of QB64 prior to 1.000 _PRINTSTRING can only be used in graphic, 256 color or 32 bit screen modes, not SCREEN 0.'' {{PageExamples}} ''Example 1:'' Printing those unprintable [[ASCII]] control characters is no longer a problem! {{CodeStart}} {{Cl|SCREEN}} {{Cl|_NEWIMAGE}}(800, 600, 256) {{Cl|FOR...NEXT|FOR}} code = 0 {{Cl|TO}} 31 chrstr$ = chrstr$ + {{Cl|CHR$}}(code) + {{Cl|SPACE$}}(1) {{Cl|NEXT}} {{Cl|_FONT}} {{Cl|_LOADFONT}}("C:\Windows\Fonts\Cour.ttf", 20, "MONOSPACE") 'select monospace font {{Cl|_PRINTSTRING}} (0, 16), chrstr$ {{Cl|END}} {{CodeEnd}} {{OutputStart}} ☺ ☻ ♥ ♦ ♣ ♠ • ◘ ○ ◙ ♂ ♀ ♪ ♫ ☼ ► ◄ ↕ ‼ ¶ § ▬ ↨ ↑ ↓ → ← ∟ ↔ ▲ ▼ {{OutputEnd}} ''Example 2:'' Making any '''QB64 program window''' larger using a SUB that easily converts PRINT to [[_PRINTSTRING]]. {{CodeStart}} Scr13& = {{Cl|_NEWIMAGE}}(320, 200, 13) 'this is the old SCREEN 13 image page to set the image Big13& = {{Cl|_NEWIMAGE}}(640, 480, 256) 'use 4 X 3 aspect ratio that QBasic used when full screen {{Cl|SCREEN (statement)|SCREEN}} Big13& {{Cl|_DEST}} Scr13& image1& = {{Cl|_LOADIMAGE}}("Howie.BMP", 256) image2& = {{Cl|_LOADIMAGE}}("Howie2.BMP", 256) {{Cl|_PUTIMAGE}} (10, 20), image1&, Scr13& {{Cl|_PUTIMAGE}} (160, 20), image2&, Scr13& {{Cl|_COPYPALETTE}} image1&, Scr13& {{Cl|COLOR}} 151: {{Cl|LOCATE}} 2, 4: PRINTS "Screen 13 Height Reduction to 83%" {{Cl|LOCATE}} 22, 22: PRINTS {{Cl|CHR$}}(24) + " 4 X 3 Proportion" 'use {{Cl|concatenation}} {{Cl|LOCATE}} 24, 21: PRINTS {{Cl|CHR$}}(27) + " Stretched at 100%" 'instead of a {{Cl|semicolon}}! {{Cl|_COPYPALETTE}} Scr13&, Big13& 'required when imported image colors are used {{Cl|_PUTIMAGE}} , Scr13&, Big13& 'stretches the screen to double the size K$ = {{Cl|INPUT$}}(1) {{Cl|END}} {{Cl|SUB}} PRINTS (Text$) row% = ({{Cl|CSRLIN}} - 1) * {{Cl|_FONTHEIGHT}} 'finds current screen page text or font row height col% = ({{Cl|POS}}(0) - 1) * {{Cl|_PRINTWIDTH}}("W") 'finds current page text or font column width {{Cl|_PRINTSTRING}} (col%, row%), Text$ {{Cl|END SUB}} {{CodeEnd}} {{small|Code by Ted Weissgerber}} : ''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'''.