PortaCalc Mini-Tutorial LOOKUP The LOOKUP function is commonly found in commercial spread sheets. This is not directly present on PortaCalc, but is simple to obtain. The LOOKUP function is given a cell and a table to look up in, and it searches the table for the next larger element than the cell given (or the entry just before this; the definition is easily tailored in PortaCalc) and returns the next element in the matrix right or down from the cell found. In the example sheet of Fig. 1, the matrix from A2 to D3 is the lookup table. The desired action is to search for the entry in the row A2:D2 which is greater than the chosen cell, and return the next cell down from that entry. To do this, we use the formula in cell B6. Accumulator A is used to hold the value we look for, accumulator B holds the length of the row we look in, and we start an indirect file having moved to cell A2, the upper left cell of the row. The command file invoked scans right until either B counts down (using up the count) or until we find the desired cell. Since in this case we look for a cell larger than 15., we find cell C2. The command file then returns the next lower value (3. in this case). Note if we were searching a column instead of a row, a simple approach would have been to call a different indirect file. The command file is exhibited below the sheet. Note its use of the locate function *P cell to move to relative cells, and the *J construct, which jumps ONLY if the last calculation resulted in a number that is larger than 0. The following are the figures: Demonstration of LOOKUP functionality in PortaCalc ROW/COL A= 1 B= 2 C= 3 D= 4 1> Cell range A2:D2 has values, A3:D3 has results 2> 6. 11. 35. 76. 3> 1. 2. 3. 4. 4> 5> Next line holds lookup for A6 6> 15. A=A6\B=4.\*P A2\*@LKPRW.CMD 7> FIG. 1 - SHEET using a lookup function in cell B6 *C LOOKUP ROW. *C USE: A=VBL TO TEST\B=ROW LENGTH\*P LOOKUP START\*@LKPR.CMD *C LOOP %=(P#0#0)-A *J GOTIT *P P#1#0 B=(B)-1. *J LOOP *C GOTIT %=P#0#1 Fig. 2 - LKPRW.CMD command file called by sheet of Fig 1 Had it been desired to retrieve the cell to the left of the one gotten, the last line might have been replaced in the command file with %=P#-1#1 which would retrieve the cell to the left of the one currently returned. Similar techniques can be used for other sorts of searches. Note the *G construct more or less directly handles the functionality of the CHOOSE function of most spreadsheets.