Classic Computer Magazine Archive COMPUTE! ISSUE 54 / NOVEMBER 1984 / PAGE 171

IBM Screen Formatter

David Leithauser

Here's a simple programming trick that will help you write programs to be compatible with either 40-or 80-column text screens. It works with all versions of IBM BASIC.

IBM Personal Computers have the option of using a 40-column or 80-column display in text mode. This is done primarily because you have a choice of various types of monitors (screens), ranging from special RGB (Red-Green-Blue) computer displays to ordinary TV sets. The 40-column option is necessary because on most TV sets the letters of an 80-column display are too small and fuzzy to be seen clearly. The resolution on TV screens is not as good as on special video monitors. For people who have invested in a dedicated computer monitor, however, the 80-column display allows twice as much information to be displayed on the screen.

While these options make IBM computers more versatile for users, they cause some problems for programmers. If a program is written in the 80-column mode, some of the words that are printed on the screen may be split when the program is run in the 40-column mode. For example, if your program displays the message PRESS M FOR MENU, R TO REPEAT COMPUTATIONS, the word COMPUTATIONS will be split between the O and the N when the program is run in the 40-column mode. One way to avoid this problem is to insert enough spaces before the word that would be split so it starts on the next line in 40-column mode. Unfortunately, this sometimes looks very strange in the 80-column mode. When printing PRESS M FOR MENU, R TO REPEAT COMPUTATION, for example, you would have to insert ten spaces before the word COMPUTATION, which would look odd on an 80-column screen.

A Better Solution

A more effective way to solve this problem is to take advantage of a feature built into the PRINT statement in IBM BASIC. When the PRINT statement is printing a series of strings separated by semicolons, it checks to see if each string will fit in the space remaining in the current screen line. If it won't, the string automatically starts on the next line.

For example, if A$ and B$ are both 30 characters long, the statement:

PRINT A$;B$

prints A$ and B$ on the same line if the screen is in the 80-column mode, but on different lines on a 40-column screen. B$ starts printing on the next line because it won't fit completely on the same line with A$.

Therefore, by splitting the text in your PRINT statement after a space within the first 40 characters, you can be sure the words will not be broken. Just count the characters until you get to the fortieth, then backtrack until you get to a space and split the text after the space into two sections separated by a semicolon. For example, the statement:

PRINT "PRESS M FOR MENU, R TO REPEAT COMPUTATION."

becomes

PRINT "PRESS M FOR MENU, R TO REPEAT;"; "COMPUTATION."

You may need to split the text in the PRINT statement in several places if the second portion of the string is more than 40 characters long.

In some cases, you may be printing out a string variable (such as A$) rather than a string literal (characters enclosed in quotes). Sometimes you may not even know the length of the string, such as when the string was input by the user. In these instances, the following subroutine will print the contents of the string variable (in this case A$) without splitting any words—regardless of the screen width or the length of the string (provided there's at least one space per 40 characters). The line numbers in this subroutine are arbitrary, so use whatever line numbers you like (omit lines 10–30 when using this as a subroutine). Just assign the text you want printed to A$ and GOSUB 65000. (Be sure to put an END statement after your main code so the subroutine isn't accidentally executed twice.)

IBM Screen Formatter

Refer to "COMPUTE!'s Guide To Typing In Programs" before typing in this program.

HO 10 CLS : A$ = "THE IBM PERSONAL COMPUTER 
	HAS THE OPTION OF USING A 40-COLUMN
	OR 80-COLUMN DISPLAY"
KB 20 GOSUB 65000
CF 30 END
LI 65000 WS = 1
NJ 65010 WE = INSTR (WS, AS, " ")
KA 65020 IF WE>0 THEN PRINT MID$(A$, WS, WE - WS + 1); : WS = WE + 1 : GOTO 65010
JC 65030 PRINT MlD$ (AS, WS)
JK 65040 RETURN