TABCALC by J.F. Tydeman from ZX Computing Feb/Mar.1986 An excellent spreadsheet program from J.F. Tydeman, specifically for the Wafadrive and Kempston E, but very easily modified to suit all systems. TABCALC is a spreadsheet program designed to take full advantage of the facilities offered by the Rotronics Wafadrive and a line printer. An alternative listing is provided to permit the program to be used with the Kempston 'E' interface and a little hacking is all that is required to adapt the program to other interfaces and Microdrive. Tape facilities haven't been forgotten either, but the ZX printer just doesn't have enough characters per line to produce a useful printout from this type of program. Entering the listing Listing 1 is for the Wafadrive and uses the Wafadrive's Centronics port to feed the printer. Simply enter the listing and run the program. Should you wish to use Microdrive, modify the appropriate LOAD/SAVE commands in the routine starting at line 5000 but note the different way in which the Wafadrive handles the loading and saving of data. Enter listing 2 instead of lines 3000 to 3420 if you wish to use the Kempston 'E' interface. Listing 2 should be easily modified to suit other interfaces. Interface software should be entered instead of line 3020 and lines 3340, 3360, 3390 and 3410, which remove or implement Spectrum command word tokens, should be either left out or substituted with those required by your interface. If you wish to use a printer other than the Epson or Star you will have to check the printer codes against those given in your printer manual. If you do not have the Wafadrive, you will be unable to enter some of the lines as these use the Wafadrive's Extended Basic. Don't enter these lines, which only occur in the Load/Save routine. Modify the Menu accordingly. Program Description The program, which stores information entered in a three dimensional array, uses the Spectrum's string handling facilities extensively, particularly when handling the screen display. It is menu driven and features eight principal routines. A description of these is given in figure 1. Enter and/or Amend Data (Lines 2000-2510) This routine is the heart of the program and is probably the most complex. It works by slicing the three dimension array A$, defined during initialisation, and printing on the screen in two 'Windows'. These windows correspond to the following screen locations. Line 0, Column 8, and Line 20, Column 31. A '*' cursor which may be moved to any position on the screen using the cursor keys, or to the next column by depressing ENTER should be positioned where it is required to enter or amend data. If the cursor moves off the screen in any direction the appropriate window is reprinted. A slight pause is experienced at this point. The Enter/Amend option MUST NOT be selected unless the program has either been Formatted, or a Data File loaded otherwise an error will result. Sub-totals at any line may be selected by entering a 'T' in the first space of the column where it is required. These markers should be entered each time a calculation, or recalculation is made as the calculation routine removes them. Printer Routine (Lines 3000-5420) The listing of this routine in the main program uses the Wafadrive's centronics port. If, however, you do not have a Wafadrive, listing 2 will give you the same printer facilities via the Kempston 'E' interface. Both listings are for Epson or Star printers but should be easy to modify for other printers. The routine provides an extensive range of formats and up to 136 characters per line may be printed in condensed mode. If you have selected a format containing more than 6x8 character columns, (excluding Titles and Totals), you will need to select the condensed printing mode. Calculation Routine (Lines 4000-4370) This routine should only be used if standard eight-character columns have been formatted. If either, or both, Column and Line totals have been cancelled (Option 8) then flags will have been set to prevent the appropriate part of the routine from functioning. A safeguard is included which will prevent Totals containing more digits than the column width from being printed. An audible warning is given during calculation should this occur. As the routine can take some time if the array has been extensively filled with data, the column or line number currently being totalled is displayed on screen. SAVE/LOAD routine (Lines 5000-5300) A comprehensive routine to load/save to tape or wafer which could easily be adapted for use in other programs. If you are converting this routine to microdrive it should be noted that Saving or Loading Data on the Wafadrive is carried out by reading the different elements of the array A$. This is achieved with nested loops which are [not] necessary with tape or microdrive. Note that Column Titles and all the variables necessary to run an unformatted version of the program are also saved. Attributes (Lines 8000-8020) A simple routine which enables Paper and Ink colours to be set from the Menu. Clear numeric data (Lines 6140-6200) Nested loops are used to clear the array with the exception of line and column titles. The routine then calls part of the format routine to allow the option of entering column markers. Cancel/reinstate totals (Lines 6000-6130) This routine prints a menu which gives options to cancel or reinstate Line and Column Totals. Flags are set and the array sliced according to the option selected. Data recorded in these segments is retained in memory. Exercising this option fully, after formatting without Line/Column Titles or Column Markers, enables text only to be entered. If you wish to enter a mixture of text and numeric data then enter numeric data first, calculate totals (if required), cancel Line and Column totals and then enter text. If applicable, Column and Line Totals should be reinstated before sending data to the printer. Important points 1. The largest number which can be entered is 9999999 or in decimal form 9999.99. Totals or sub-totals which exceed this will not be entered. 2. Text comments must not be entered before totals have been calculated. 3. The program must be INITIALISED or DATA LOADED before selecting any of the other MENU options. 4. Should the program return to BASIC for any reason it may be restarted with GO TO 1. Do not use RUN as this will clear all data entered. Figure 1. Description of main routines. 2000-2060 Defines certain variables representing either a screen location or the corresponding position in the array A$ and then prints the initial screen display. 2070-2220 The Input Logo. This loop enables the cursor to be moved and data to be entered or deleted as required. Subroutines located at lines 2230-2510 are called to print on screen as required. The principle options available are: Caps shift + '5' - Move cursor left Caps shift + '6' - Move cursor down Caps shift + '7' - Move cursor up Caps shift + '8' - Move cursor right Symb.shift + 'A' - Return to menu Symb.shift + ':' - Print':' at cursor Delete - Delete at cursor, and backspace. Enter - Move cursor to first position of next column. If end of array, print cursor at beginning of next line ASC 2 Character - Print at cursor position 'T' - Entered to indicate the position of a sub-total. 2230-2310 Reprint screen display if cursor moves off right-hand edge. 2320-2370 Reprint screen display if cursor moves off left-hand edge. 2380-2420 Reprint screen display if cursor moves off top edge. 2430-2470 Reprint screen display if cursor moves off bottom edge. 2480-2490 'Enter' Subroutine. 3000-3170 Print on-screen a menu of various printer codes and format options. A little practice will enable you to select an appropriate format and print it anywhere desired on A4 paper. The BOX option is used to print out numeric data in the form of a table and should be used in conjunction with LINE SPACING for optimum effect. Print options are cancelled when printing is completed and must be re-entered if a copy is required. 3180-3310 Requests the input of a title and sends to the printer the data to be printed. 4010-4070 Checks to see if the appropriate Totals flags have been reset. If not, goes to the appropriate subroutine. 4080-4200 Sets all column totals initially to 0 and enters series of nested loops to total each column. Safeguards included in lines 4150 and 4160 prevent the program crashing if a null entry is found, or the total becomes too big. 4210-4350 Similar routine for Line Totals. 4360-4370 Minor subroutine to set keyboard 'click'. REFORMAT/INITIALISE ... LINES 9000-9440 When using the program for the first time it must be formatted. To do this select option 1 from the Main Menu. LINE NUMBERS DESCRIPTION 9010 Gives the opportunity to return to the menu if the option has been chosen in error. 9020-9170 This section permits you to define up to 15 column titles, each eight spaces wide. Line Titles and Totals columns are not included as they are formatted automatically. The maximum width of the array A$ is 136 characters, which corresponds to the number of characters which can be printed in condensed mode. 9180-9310 Routine for entering Line Titles. Up to 99 titles may be entered. If you wish to enter text commands you may enter a blank title in the appropriate line. This facility is also available when entering column titles. Used together it is possible to format the program to the required dimensions without entering titles and should be used if only text entry, or columns of non-standard width are required. Titles may then be entered from the main program. 9320-9340 Permits column markers to be entered and should only be selected if columns of a standard eight character width are required. 9340-9450 Defines certain variables used by the Printer Routine. -- end of file --