Character strings

The character-string (or CHR$) function converts any decimal number from zero through 255 to a character or action. Its format is CHR$ followed by a number in parentheses, for example, CHR$(84). The character-string command follows a PRINT or LPRINT command and causes your computer system to send an ASCII code to the computer’s screen or to the printer. What gets printed or performed is determined by the particular modified ASCII table that is used by your system. Where the printing or action happens-on your screen or your printer-depends on the print command that precedes the character-string command.

For a fast check on what your computer does with this function, try printing a few characters on your computer’s screen. The usual format for this is PRINT CHR$(n). The n represents one of the numbers from zero to 255, each one of which accesses a unique character or action. Try typing this:

10 PRINT CHR$(65)

and RUNning it. Since most computers use the numbers from 32 to 127 to mean the ASCII set of characters, you should see a capital A on the screen.

It’s the numbers less than 32 and greater than 127 that produce different results on nearly every brand of computer. Try entering:

10 PRINT CHR$(193)

and RUNning it. If you don’t see anything on the screen, don’t worry. Remember that this was just a quick check. We are mainly interested in sending that 193 to the printer, and what it prints on the screen is not as important right now.

BASIC print commands

Well then, what happens when you send such a non-standard code as 193 to the printer? To test this out, you need to know what program commands your computer uses to activate the printer. Some typical command sequences are shown in Table 2-2.

39