|
|
This article discusses the BBC BASIC keywords for text display, PRINT and TAB, as well as the STRING$ keyword used by BBC BASIC to concatenate strings, and printing text.
The PRINT Keyword in BBC BASICOutput can be directed to the screen in BBC BASIC by using the PRINT keyword. At its most simple, PRINT is used to display:
The screen is by default divided into 10 character wide fields. This can be changed, by modifying the @% system variable. We shall leave this to one side for now, and rely on the simple fact that each field is 10 characters wide. Subsequently, we might write a statement such as: PRINT 1234 In the above example, text output would be right justified in the first field: 012345678901234567890.... 1234 We can 'skip' fields by introducing commas in the PRINT list. So, to start in the third field, we would use code such as: PRINT ,,1234 Subsequent calls to PRINT will cause output to occur on a new line each time. We can, of course, suppress this behaviour by placing a comma at the end of the statement: PRINT "Same "; PRINT "Line "; The above sequence of calls to PRINT will yield: 012345678901234567890.... Same Line The reader will note that the alignment to fields does not take place for the display of string constants, but that when the two are combined, numerical data is aligned to the next available field. The TAB Keyword in BBC BASICIn BBC BASIC, TAB exists in two forms: PRINT TAB(5);"Hello" PRINT TAB(5,1);"Hello" In the first form, BBC BASIC will print enough spaces between the last printed character and the number specified to make them equal. In other words, TAB(5) directly after a new line will print 5 spaces. If 5 characters have already been output since the last new line, then a new line will be inserted first. In the second form, TAB(X,Y) refers to a specific column (X) and row (Y), and start outputting characters. Do not mix TAB(X) and TAB(X,Y), as unexpected results will be encountered. By way of an exercise, the reader might like to try the following code samples: PRINT "1234";TAB(5);"<Start here" PRINT "12345";TAB(5)"<Start here" The results show clearly the difference between calls to TAB(X) depending on the amount of characters already printed. Using STRING$ in BBC BASICThe STRING$ function returns a repetition of a string, N times. The syntax makes this easier to understand: PRINT STRING$(10,":") The above will output 10 ':' characters ('::::::::::'). While this might not seem terribly useful, it is worth remembering that if the screen is 80 characters wide, and we want to insert a variable amount of padding, this gives us a very useful way of doing so. We can also put as many characters as we like in the second parameter. Suppose we were writing a text editor, and wanted to print a line across the top of the screen, indicating the number of characters. We usually do this in collections of ten: PRINT STRING$(4,"0123456789") This code snippet would yield: 0123456789012345678901234567890123456789 As we consider the interface to the printer for creating printed documents, the power of the above should become clearer. Turning the Printer on and Off in BBC BASICThe printer can be activated with a VDU call: VUD 2 From this point on, all calls to PRINT or VDU will be directed to the printer, as if it were the screen. The TAB and STRING$ keywords can also be used, along with some others. In fact, any keyword that makes sense with respect to screen printing can be used when controlling the printer. When printing is complete, we can use another VDU call to redirect output back to the screen: VDU 3 In between VDU 2 and VDU 3, printing follows the Page Printing model. Page PrintingWe can also use PRINT, TAB, and STRING$ to control the printer. In common with the original BBC BASIC, it is assumed that a page printer is being used. In other words, the printer relies on the program to tell it when to start a new page, by use of either the CLS keyword, or sending VDU 12. Before TAB will work to line up the text, however, we must be sure to select the right font. Those who have worked with Windows before will know that there are two kinds of font : fixed pitch and variable pitch. Variable pitch spaces the letters unevenly. Letters requiring less horizontal space will take less horizontal space; this makes using TAB to line up columns impossible. On the other hand, fixed pitch fonts use the same space for each character - each character is the same width. To select the font, we can make a call to a BBC BASIOC star command: *PRINTERFONT Courier, 10 Of course, the programmer will need to experiment slightly to be able to judge the best line width and page length depending on the font size selected. For programs that are to be distributed to the general public, some calibration of different printer devices should be included with the package. BBC BASIC Tutorial Links
The copyright of the article Text Output with BBC BASIC in Computer Programming Tutorials is owned by Guy Lecky-Thompson. Permission to republish Text Output with BBC BASIC in print or online must be granted by the author in writing.
|
|
|
|
|
|
|
|