home *** CD-ROM | disk | FTP | other *** search
/ Run Magazine ReRun 1992 September & October / rerun-1992-09-10-side-a.d64 / 128mode.txt next >
Text File  |  2022-09-20  |  7KB  |  73 lines

  1. 128 Mode
  2. By Mark Jordan
  3.  
  4. The easiest of all Basic commands to learn to use is Print. In fact, it's so easy to use, even seasoned programmers may forget that it has a sophisticated younger sibling: Print Using. But, why bother learning a new command when you've already got one that does its job quite well? I mean, what can't Print do?
  5.  
  6. By itself, lots. When you want to format columns of text or numbers, especially numbers, Print has to labor. For instance, to print a neat column of dollars and cents using Print, you have to do something like this:
  7.  
  8. PRINT LEFT$("    "+STR$(ABS(NUMBER))) +"."+STR$(NUMBER-ABS (NUMBER))
  9.  
  10. Whereas Print Using would handle the same situation like this:
  11.  
  12. PRINT USING "####.##";NUMBER
  13.  
  14. Also, Print Using can float a dollar sign alongside the number (or move it to the left position), place commas in specified locations, use dots (periods) as column leaders (e.g., Smith......$347.21), incorporate strings readily (centered, left- or right-justified) and more.
  15.  
  16. The main reason Print Using gets overlooked is because it's just about the most poorly documented command in the User's Guide. Its three-and-a-half pages of explanation do little to help, so I'll try to remedy that right now.
  17.  
  18. Putting Print Using to Work
  19.  
  20. The big difference between Print and Print Using is what's called the "format list." This is nothing more than the predefined output pattern you want. Let's dissect the following statement piece by piece and have a look.
  21.  
  22. PRINT USING "#####" ; 135
  23.  
  24. 1. The first word, print, is the same as in the plain ol' Print statement.
  25.  
  26. 2. Between the keywords print and using you have the opportunity to direct your results to a file if you want to, such as a printer file or disk file. You do this the same way you direct output to any device, with the pound sign and a logical file number. Thus, in print #2, using the output is sent to file 2.
  27.  
  28. 3. Next comes the keyword USING.
  29.  
  30. 4. An opening quote and the format list come next. The list must be within quotes unless you predefine a string as your format list. If you use a string, your format list might take the form: PRINT USING F$ ; 135.
  31.  
  32. 5. No matter whether you elect to predefine the format list, or do it within the Print Using statement, it's what's between the buns (i.e., quotes) that matters. In our model, the format list consists of five pound signs (#####). These tell the computer that the printing column width is five characters wide. If you're printing numbers, Print Using will right-justify the output, printing two spaces then the number 135. This way numbers are always lined up on the right, making the creation of columns a snap. We'll discuss the format list more in a minute.
  33.  
  34. 6. The end-quote. No surprise; it terminates the format list.7. The semicolon is needed to separate the format list from the print list--a necessary formality.
  35.  
  36. 8. The print list. This is what you want printed. The example above shows a single item, the number 135; but the print list can be as many items as you wish, both text and numeric values, constants and variables. Your only grammatical requirement is to separate each with a comma, like this:
  37.  
  38. PRINT USING "#####" ; 135,NM
  39.  
  40. Each succeeding column begins where the preceding one ends. Therefore, if you set your format list five places wide (five pound signs) your output columns will begin every five spaces. Thus if NM above equaled 15893, the output would look like this: 13515893. To correct this problem and keep columns separate, you simply widen the format list.
  41.  
  42. Digging Deeper
  43.  
  44. That's a quick overview. Now let's dig into the depths of that format list. Besides the pound sign, you have eight other symbols at your disposal. Each of these tells Print Using to do something a little differently with the print list.
  45.  
  46. * Pound (#) As mentioned, this simply reserves a place for output.
  47.  
  48. *Plus (+) Placing a plus sign at the beginning of your format list will cause all positive numbers to be preceded by a plus (+). Placing the plus sign at the end of the format list will cause a plus sign to print after positive numbers.
  49.  
  50. *Minus (-) This works like the above, only it attaches minus signs to negative numbers. (When this is used, positive numbers do not receive plus signs.)
  51.  
  52. *Decimal (.) Placing a period in your format list effectively tells your C-128 how many digits to the right of the period you want displayed. For example, PRINT USING "####.##" ; MONEY would produce 78.00 if MONEY equaled 78. This arrangement is handy for printing a column of financial values (dollars and cents).
  53.  
  54. *Dollar ($) This symbol (that favorite of Americans everywhere) will automatically output a dollar sign with all numeric values. You can have a floating dollar sign (one that always appears immediately to the left of the number) by placing it in the second place (like this: "#$####.##"). Locating it elsewhere will force it to appear where you place it within the format list.
  55.  
  56. *Comma (,) The comma simply allows you to force a comma wherever you want in the format field. Therefore, to put it between the hundreds and thousands place, you'd place it between the third and fourth pound signs to the left of the decimal, as in "###,###.##".*Up Arrows (^) Four up-arrows in the format field will cause the result to be printed in scientific notation.
  57.  
  58. *Equal (=) This symbol plus the next one deal only with string output. The equal sign (=) causes the text to be centered within the format field.
  59.  
  60. *Greater than (>) This symbol causes text to be right-justified rather than its default of left-justified. Some Quirks & pudefAny symbols placed between the quotes in the format list count towards the output column width, not just the pound signs. Fractions are automatically rounded. You cannot use the semicolon after a Print Using to keep the cursor in place like you can with Print. If your output exceeds the places preserved in the format list, you'll see stars (asterisks, actually). With text strings, the string is truncated--that is, chopped off--when it exceeds the column width.
  61.  
  62. A related command, PUDEF, allows you to change the filler character (which defaults to a blank space) to whatever you want. This allows for neat lists that print with periods between columns. Here's a sample:
  63.  
  64. PUDEF ".":PRINT USING "######.##"; NAME$,AMOUNT
  65.  
  66. If name$ = "Bob" and AMOUNT = 13.72 the output would look like this:
  67.  
  68. Bob....13.72
  69.  
  70. PUDEF also allows you to change the comma character, the decimal point, and the dollar sign. See the program below (and your User's Guide) for more details.
  71.  
  72. It's tough in this limited space to say all I'd like to about Print Using. That's why I've included the short program, PRINT 128 MODE. Run it and you'll get a good idea of Print Using's value.
  73.