Matrix/Cursor Input

See all articles from T-S Horizons n2

In any interactive computer program (i.e., one that requires the user to supply the computer with information at several times during program execution), far more time will be consumed waiting for the user to get the computer information than the user waiting for the computer to finish manipulating the data. Not only are we simply slower than the computers, but since the computer must have the correct data in order to generate the correct answer, inputs must always be checked and then re-checked in order to minimize the possibility of error. This “weak link”, where information must pass from computer-to-user and user-to-computer, can be addressed in two ways. The first is through the use of such hardware as touch screens, “mouse” controllers, etc. But the most straightforward way to address the problem is through software. The user must be able to clearly understand what the computer is asking. This involves concise, readable questions or queries, and responses that require only a minimum number of keystrokes. Error recovery is another important partial solution to the problem of data input, one that we will deal with separately in a later article. But what we will address now is the question of how to get the most information on the screen, in a relatively simple and imageable format, in order for the person sitting at the computer to have the maximum understanding of not only what is being asked of him by the computer, but also what information the computer already has.

In most programming applications, data can be broken down into repetitive sets, similar in units of measure and other respects. To input each set of data, similar or identical sets of questions must be asked in order to prompt the inputs. When this is the case, the twin problem of requesting information in a readable format and then displaying the received data in a readable format, can be solved by what I call Matrix/Cursor Input.

The idea is to map on the screen a set of headings at the top and side that outline an empty matrix into which you can input information. To prompt inputs, all one needs to do is to place a cursor (i.e. a question mark or inverse question mark) in the location on the screen corresponding to the row and column that define the information that the computer requires. After this information is read in from the keyboard, it can be printed in that same location, and the process repeated until the entire matrix is filled with information.

For example, in the screen copy below, each row holds a different type of information and each column holds a set of information describing a particular business trip.

(PRINT HEADING HERE...)

BUSINESS TRIP  1    2    3
DESTINATION
DATE(MO/DY)
ODOMETER(1ST)
ODOMETER(END)
GASOLINE($$$)
GASOLINE(GAL)


*TOT.MILEAGE=
*MILES/GAL. =
*AVG.$/GAL. =

Using this concept, the data from three business trips can be requested, INPUT, and PRINTED on the screen with a minimum of changes in the screen–allowing maximum display of inputs in an easily examinable format. This method makes it possible for you to check your entries a second time, after all the information has been read in, giving you a chance to see discrepancies between sets of data. Also, the more information you can get onto the screen at one time, the more control the user gains over the program and its data.

We will now briefly outline this concept and then go on to a detailed description of how to incorporate it into your programs.

OUTLINE OF PROCESS

1. PRINT a row/column format on the screen.
–Headings and titles: be sure to include units of measure and other important notes.

2. PRINT cursor (inverse question mark) in the correct row/column of the matrix.

3. INPUT information (into an array)

4. PRINT information in its square (over the cursor).

5. …..PRINT cursor in the next square.

As a specific example of this format, we will now look at the input section of a program I have written to analyze the heat gain/heat loss of a building.

This particular portion of the program requests information describing the windows for a room in the house. Each window has a data set which describes its area, orientation, shading, etc. This program accepts up to four windows per room.

(PRINT HEADING HERE)

  GLASS        1    2    3    4

AREA(SQFT)     1024 572  544  750
DEG.HORIZ.     90   90   75   90
DEG.REF.<      10   55   10   -80
OVERHANG       24   24   0    24
WINDOW HT.     72   48   72   72
HEAD TO OH     8    8    0    8
NO.GLAZNGS     2    2    2    2

The cursor would begin in the upper left part of the matrix and continue down the column until the first window has been fully described. The program will then proceed to the second column, and so on.

Before we go on to a program listing, let’s look closer at the outline given earlier and clarify some programming decisions.

1. PRINT a row/column format on the screen. This involves a decision as to what the length of the inputs will be (i.e. 0-9999, all integers, requires four characters as well as separating spaces), and whether the inputs would be in a row or column. I placed the glass data in a column in this case because seven items would not fit in a single line.

2. PRINT a cursor in the correct cell. This requires you to set up two print position variables (x,y), one to indicate the row and one to specify the column. In setting up the glass data, we want to print our inputs on the fourth line, (row 3 in Sinclair display format) and the fourteenth column (#13 on the Sinclair). We will input seven consecutive items in the same column, and then proceed to a similar set of items five spaces to the right (the second column of data). Thus the printing locations are as follows (in the PRINT AT (row, column) format):

(3,13)   (3,18)   (3,23)   (3,28)
(4,13)   (4,18)   (4,23)   (4,28)
  .        .        .        .
  .        .        .        .
  .        .        .        .
(9,13)   (9,18)   (9,23)   (9,28)

These are the row/column locations of each cell of the matrix that the program will have to generate.

3. INPUT information. This requires setting up an array that corresponds to the screen matrix that you have settled on. For clarity in this example, we will INPUT the glass data into a single, two-dimensional array of seven rows and four columns. But if the program were to accommodate several rooms (which my full heat loss/heat gain program does), it could be expanded to a three-dimensional array with the third dimension being the different rooms.

4. PRINT information over the cursor. Printing the data (using the same print position variables as in Step 2) will overwrite the cursor and fill the cell with data.

5. PRINT cursor in the next cell. This will mean reaching the end of the program loop and starting the cycle over again.

The following is a listing of the input portion of the heat loss/heat gain program that will set-up and read-in the glass data in that screen format previously shown. It sets up a seven-row, four-column matrix and reads information into it. For your information, the variables are explained following the listing.

LISTING

4000 REM MATRIX/CURSOR INPUT
4050 DIM I(4,7)
4060 LET Y=8
4080 PRINT AT 0,0;"(PRINT HEADING HERE)"
4090 PRINT AT 2,0;"NO.OF GLASS AREAS?"
4095 INPUT NO
4100 IF NO>4 THEN GOTO 4090
4105 PRINT AT 2,0;" GLASS"
4110 PRINT AT 4,0; "AREA (SQFT)"
4115 PRINT "DEG.HORIZ."
4120 PRINT "DEG.REF.<"
4125 PRINT "OVERHANG"
4130 PRINT "WINDOW HT."
4135 PRINT "HEAD TO OH"
4140 PRINT "NO.GLAZNGS"
4150 FOR N=1 TO NO
4155 LET Y=Y+5
4160 PRINT AT 2,Y;N
4165 FOR X=1 TO 7
4170 PRINT AT X+3,Y;" "
4175 PRINT AT X+3,Y;"?"
4180 INPUT I(N,X)
4182 LET I(N,X)=INT I(N,X)
4185 IF I(N,X)>=1000 THEN GOTO 4170
4190 PRINT AT X+3,Y;I(N,X)
4195 NEXT X
4200 NEXT N

VARIABLES

I(4,7) - array that stores all glass data
Y      - print position variable that
         indicates column
X      - loop variable and print position
         variable that indicates row
NO     - no. of glass areas (1-4)
N      - loop variable, indicating which
         column is operating

Remarks on the program listing

  • line 4050: define the array sufficiently large to store all of the requisite data. Re-dimensioning will wipe-out all existing data and you will have to start over.
  • line 4060: since the print locations that we seek are at y=13,18,23 and 28, we begin with y=8 and add 5 at the beginning of each loop (line 4155).
  • lines 4080-4100: these lines print a title and ask how many glass areas there are in order to set up the number of columns in the matrix.
  • lines 4110-4140: these statements print cryptic headings down the left side of the screen to define the type of data in each row.
  • line 4150: set up loop to go from column to column.
  • line 4155: increment variable (Y) to the correct value.
  • line 4160: print at the top of the column the number (1-4) of each glass area.
  • line 4165: set up loop to go down seven rows of data.
  • line 4170: blank out anything that was in the cell (this becomes important in conjunction with error recovery).
  • line 4175: print cursor (?) in the cell to indicate data to be input.
  • line 4180: input data into the corresponding cell of the array.
  • lines 4182,4185: limit inputs to four-digit inte gers.
  • line 4190: print data in its cell.
  • line 4195: bottom of X loop (7 rows).
  • line 4200: bottom of N loop (1-4 columns).

Depending on the requirements imposed by your particular set of data, you can fill up the screen with a single matrix, or have several matrices on the screen at one time. And if only a few pieces of data comprise a data set, such as in the budget program that I discussed in last month’s article on files, you could conceivable display 15 to 20 lines (sets) of data at one time.

Below is another example of using the matrix format, where not all of the data columns are applicable to each data set.

SURFACE TYPE: "BRIC"                (1)

MATERIAL    R/IN        IN THK  R-VAL
OUTSIDE AIRFILM.................0.14
BRIC        0.11        4       0.44
PLYWOOD     1.25        0.625   0.78
STUDS...................3.5     0.
BATT INS    3.2         3.5     11.2
DRYWALL     0.85        0.5     0.42
INSIDE AIRFILM..................0.68

              NOMINAL R-VALUE= 13.66
           ADJUST.FOR FRAMING= -2.27
                TOTAL R-VALUE= 11.39

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.