SHEET version 3.0 Manual of Database Part By Chor-ming Lung Date: November 1, 1989 Table of contents _________________ Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Database creation . . . . . . . . . . . . . . . . . . . . . . . . 1 Criteria range . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Criteria . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Comparison criteria . . . . . . . . . . . . . . . . . . 2 Match criteria . . . . . . . . . . . . . . . . . . . . . 2 Computed criteria . . . . . . . . . . . . . . . . . . . 2 Combining criteria . . . . . . . . . . . . . . . . . . . . . 2 Database operations . . . . . . . . . . . . . . . . . . . . . . . 3 Set Database . . . . . . . . . . . . . . . . . . . . . . . . 3 Set Criteria range . . . . . . . . . . . . . . . . . . . . . 3 Find . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Extract . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Set Output range . . . . . . . . . . . . . . . . . . . . . . 5 Delete . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Database functions . . . . . . . . . . . . . . . . . . . . . . . . 6 DSUM, DCOUNT, DAVERAGE, DMIN, DMAX, DSTD, DVAR . . . . . . . 6 Database commands . . . . . . . . . . . . . . . . . . . . . . . . 7 QUERY . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 EXTRACT . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 DB_INPUT DB_INPUT . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Input record . . . . . . . . . . . . . . . . . . . . . . 8 Query . . . . . . . . . . . . . . . . . . . . . . . 8 Search . . . . . . . . . . . . . . . . . . . . . . 8 Next . . . . . . . . . . . . . . . . . . . . . . . 8 Query forms . . . . . . . . . . . . . . . . . . . . . . 10 Find records . . . . . . . . . . . . . . . . . . . . . . 10 DB_INPUT arguments . . . . . . . . . . . . . . . . . . . 10 Database . . . . . . . . . . . . . . . . . . . . . 10 Display . . . . . . . . . . . . . . . . . . . . . . 10 Query . . . . . . . . . . . . . . . . . . . . . . . 11 Relation list . . . . . . . . . . . . . . . . . . . 11 DB_INPUT entry . . . . . . . . . . . . . . . . . . . . . 11 BUTTON . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 CUR_REC . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Phone Book II . . . . . . . . . . . . . . . . . . . . . . . . . . 13 SHEET -- Database Part By Chor-ming Lung November 1, 1989 Database management ___________________ Introduction: ____________ SHEET v3.0 provides database functions and operations which are quite similar to Lotus 123. If you are familiar with the database manager of Lotus 123, feel free to jump to the part starting from the discussion of DB_INPUT. DB_INPUT We will use an address book and a small personnel database as examples to guide you through different aspects of the database manager of SHEET. First of all, we will discuss the creation of database. After that, we will discuss about searching criteria and combining criteria to form criteria range for manipulating information from the database (creating queries and using database functions/opertions). BASIC database commands are introduced. Finally, we will try to write an application to handle our address book. Database creation: _________________ Before you enter any record, we need to decide what elements constitute the database we need. If we are creating address book, we need to store the name of the person, address and his phone number. Those elements (name, address, phone number) are called fields of a fields database. You can refine the field NAME to First Name, Middle Name, ____ Last Name and ADDRESS to Street, City, State and Zip code. In our _______ address book, we use one field to store names of persons we are interested. The ADDRESS is splited as mentioned above. Sure, it takes up more columns to store the address but it is easier to find particular records. So, we have the following fields in our address book: Name ____ Street ______ City ____ State _____ Zip code ________ The next step in creating database is to find a place to put our database. To simplify everything, we start the database from cell A1. The first row of a spreadsheet database stores the field names. So, we enter Name in A1, Street in B1 .... We have some data stored in ____ ______ FONBKII.SHT for our address book database. Our second example is in DATABASE.SHT. It is a simplified personnel database. It consists of the following fields: Last Name _________ Date Hired __________ Age ___ Sex ___ Salary ______ D 1 SHEET -- Database Part By Chor-ming Lung November 1, 1989 Criteria range: ______________ Once you have created the database, you can locate, extract or delete data from the database. To find the records desired, we need to set up criteria to confine the search to some special group of data. Spreadsheet database manager uses spatial structure to represent AND and OR relationships between criteria. So, we need more than a cell to define our criteria. Those cells which hold our criteria is called criteria range. A criteria range is a special form of database. The first row of a criteria range is reserved for field names. The rest rows define a set of criteria. Criteria on each row will be AND together and criteria on different rows will be OR together. Criteria: ________ Comparison criteria: Comparison criteria Only numeric values can be compared. Comparison operators >, <, <>, >=, =>, <=, =< can all be used. Here is an example of our two cells criteria: Age ___ >50 It means from the database, find all persons who are over 50 years old. Match criteria: Match criteria Text string can be searched by partial match. For example: Name ____ an It will match names like "Anita" or "Alan". The match is case-insensitive. Computed criteria: Computed criteria The field name of computed criteria should be blank. The formula on the computed criteria consists of cell reference of the first record. For example, the first record on field Age is on cell C2, the following ___ criteria find persons who are greater than 30 and less than 50. ___ +c2>30 and c2<50 Combining criteria: __________________ If you are looking for records which satisfy the following condition on our personnel database: age>50 and sex is male OR age>40 and salary<30000 the criteria range looks like this: Age ___ Sex ___ Salary ______ >50 m D 2 SHEET -- Database Part By Chor-ming Lung November 1, 1989 >40 <30000 NOTE: NOTE If a criteria range contains a blank row, then the whole database will meet the criteria. Database operations: ___________________ Before we go further, we play with the file DATABASE.SHT to get acquaintance with the database operations first and understand what they are later. - load the file DATABASE.SHT. - move the mouse cursor over cell A1 - press key and then press the left mouse button - move the mouse cursor over cell E11 - press key and then press the left mouse button Mouse click with and define a block containing cells from A1 to E11. The block will be highlited by inverting to black. - move the mouse cursor over the menu title Data and select the Data menu item Set Database. Set Database The highlited block is gone. It means the database is designated to cells A1..E11. If you want to see the designated area again, select the menu item Set Database. Set Database - select the menu item Set Criteria range. Set Criteria range The block A14..E15 will be displayed. Well, the database, criteria range and output range are pre-selected and saved with DATABASE.SHT. The database is A1..E11, Criteria range is A14..E15 and the Output range is G1..J11. The criteria is: Age ___ <30 It means we want to find persons whose ages are under 30. Well, select the Find menu item. The record cursor is on the person name Holt. If Find you press the Down arrow key, the record cursor will move to the girl whose name is Peacock. If you press the Down arrow key again, the record cursor stays where it is. It means no more records meet the criteria. NOTE: the topmost line changes from Ready to Find. You must NOTE Ready Find click on any cell to change from Find mode to Ready. Find Ready Let us try to extract records to our output range. Select the Extract menu item. You should see that the data of Holt and Peacock Extract are copied to our output range. The information of Date Hire is not in our output range. That is because the first row confines the fields being extracted. To experience more, you can modify the criteria, expand the criteria range and play with it again. But you should not save your D 3 SHEET -- Database Part By Chor-ming Lung November 1, 1989 modified version of DATABASE.SHT. We will use it later. D 4 SHEET -- Database Part By Chor-ming Lung November 1, 1989 Now, it is time to take a look of the menu items under the menu title Data. Data Set Database: Set Database Designate the current block to be the database being manipulated. NOTE a database includes the field names and records. If you select a block before choosing this menu item, the definition of the block will be inserted into Database range edit field. Database range Otherwise, you have to enter it by yourself. Set Criteria range: Set Criteria range Designate the current block to be the criteria range. A criteria range contains field names and criteria. Set Output range: Set Output range Output range is used to designate an area for data extraction. The first row of the output range specifies which fields being extract. See Extract for more detail. Extract Find: Find Use the criteria defined on the criteria range to show records that match the criteria. If there are some records that match the criteria, then the status will be changed from Ready to Find. If you press the Ready Find arrow key Up/Down, the record cursor will move to the next record that meets the criteria. To change back from Find mode to Find Ready mode, you should mouse-click on any Ready cell. Extract: Extract Extracts records which meet the criteria. The records will be stored in the area defined by Output range. NOTE: Except the first row, NOTE Extract will erase cells within the output range. If your output range has one row only, cells beneath this row and within the columns of output range will be erased. If you have 5 records that meet the criteria, but your output range is only 4 rows big, only three records will be stored in the output range (the first row contains field names). Delete: Delete Deletes records that meet the criteria. If deletion happens, your database range will be shorten. Delete affects only cells within Delete database range. D 5 SHEET -- Database Part By Chor-ming Lung November 1, 1989 Database functions: __________________ There are seven database functions built-in. They are: DSUM, DCOUNT, DAVERAGE, DMIN, DMAX, DSTD, DVAR DSUM, DCOUNT, DAVERAGE, DMIN, DMAX, DSTD, DVAR Here is the syntax of our database functions: Dfun(database, index, criteria) database: database it is the block which holds the data index: index it can be an offset number or field name. The first field has offset of 1. Salary on our DATABASE.SHT is the fifth field. Its offset number is 5. Instead of using 5, we can use the field name "Salary" as the index. criteria: criteria it is the block which holds the criteria range. In our DATABASE.SHT, cell E13 has a formula: + DAVERAGE(A1..E11,"Salary",A14..E15) It means we want to find the average of Salary from the records which meet criteria A14..E15. D 6 SHEET -- Database Part By Chor-ming Lung November 1, 1989 Database commands: _________________ There are four commands and one function in the BASIC interpreter which relates with database manipulation. They are QUERY, EXTRACT, DB_INPUT, BUTTON and function CUR_REC QUERY, EXTRACT, DB_INPUT, BUTTON CUR_REC QUERY QUERY Syntax: QUERY database, criteria, cell database is the block which holds the data. criteria is the block which holds the criteria range. cell is the leading cell which we put the record numbers which meet the criteria. cell will hold the number of cell records which meet the criteria. The cells below cell cell will hold the actual record number. In our DATABASE.SHT file, if you run cell F12, you will see that cell k1 is 2. It means we have 2 records meet the criteria. K2 is 1 and K3 is 3. The actual records are record 1 (Holt) and record 3 (Peacock). EXTRACT EXTRACT Syntax: EXTRACT database, criteria_range, output_range It works similar to the Extract operation on the menu. Extract DB_INPUT DB_INPUT Syntax: DB_INPUT database, display, query, "relation list" It is possibly the most complex command for SHEET. For the time being, we will go to load the DATABASE.SHT file and have some hands-on experience first. - load the DATABASE.SHT file - Press and P simultaneously - Press to print our spreadsheet first - Press and left arrow key simultaneously - move the mouse cursor over L11 - press and press the left mouse button to run the single command program. A dialog box similar to a window shows up. If you click on the close box, the dialog box will be closed and it ends the command DB_INPUT. Let us take a closer look of the dialog box. Besides of the close box, the title of the dialog box is Input record. There are Input record 9 boxes under the title. The first three of them are Query Search Query Search and Next. The rest 6 boxes are empty. Below the boxes, we see the Next first record of our personnel database. There is a vertical D 7 SHEET -- Database Part By Chor-ming Lung November 1, 1989 slider which we can use to move from record to record. The last line shows how many records in our database and what the current record number is. Input record: Input record ____________ If you move your mouse cursor to the box Query and press the Query left button, you will see that the title is Query form now, and Query form the contents of the first three boxes change to Main and Find. If Main Find you click on the Find box, the title changes to Find record and Find Find record the boxes change to Main and Query. If you click on the Main box, Main Query Main you will get back to Input record. If you click on the Query box, Input record Query you will get back to Query form. Query form Let us go back to the Input record mode. If the title on Input record your dialog box is not showing Input record, you can press Input record function key F1 a few times to switch back to Input record. Input record Pressing function key F1 is equivalent to clicking on the first box. F2 is equivalent to second box... Now we are in Input mode. Press the Left arrow key four Input times to move the field cursor to the field Sex, and click on the button Search. Enter the character m and press return. The record Search m of Jones will be displayed. If you press F3 (Next button), Lamar Jones Next Lamar will be shown. Keep pressing F3, you will reach Allen and a Allen message "String not found" follows. Let us go to the first record by moving the slider bar. Move the mouse cursor over the date and press the left button. The field cursor moves from Sex to Date Hired. If you press , Sex Date Hired the date content is gone. Now enter 3-4-82 and press left arrow 3-4-82 key. The field cursor moves to Age. We change the age to 22 and Age press return. The field cursor moves to Salary automatically. Salary Remeber the editing direction? The field cursor moves to the editing direction direction of the last arrow key led to. To sum up: we have three different modes: Input, Query and _________________________________________________ Find and the 9 boxes are actually mouse buttons. Function keys _________________________________________________________________ from F1 to F9 simulate the nine mouse buttons. ______________________________________________ In input mode: _____________ Query button: Query activate the query form for fancy query. Search button: Search search for simple text Next button: Next search using the same text from Search Search In query mode: _____________ Main button: Main return to Input mode Input Find button: Find show records that match the criteria defined in the query forms. In find mode: ____________ Main button: Main return to Input mode Input Query button: Query return to Query mode Query The data input form accepts date in this format: mm-dd-yy (more on this later). The line editor works the same way as usual. We can move from field to field by pressing the arrow keys or mouse D 8 SHEET -- Database Part By Chor-ming Lung November 1, 1989 click on the content of a field. We can move record to record by moving the slider bar or by pressing . D 9 SHEET -- Database Part By Chor-ming Lung November 1, 1989 Query forms: Query forms ___________ If we press F1, we should be in Query mode. Let us look at Query the query forms we currently have. The first form means that we want to find those records of which the Age field is over 50 and Age the Sex field is m. If we press , we have the Sex second form. It means Sex is f and Salary is over 40000. The Sex Salary combined effect is: find all the records of which (Age>50 and Sex is m) or (Sex is f and Salary>40000) Age Sex Sex Salary Find records: Find records ____________ Let us press F2 to go to the Find mode. The record shown is Find Francis. The rest are Farley and Allen. They match the criteria Francis Farley Allen in our query forms. For fun, you can change the query forms and see the result. DB_INPUT arguments: DB_INPUT arguments __________________ DB_INPUT database, display, query, "relation list" In our example (cell G16), DB_INPUT A1..E11,T1..W7,L2..P10,"1,2,3,5,4" Database: _________ A1..E11 is the area which hold our personnel database. NOTE: NOTE DB_INPUT determines the maximum number of record by the number of continuous non-empty rows on the database. If the database is A1..E1000, it will still say that the maximum number is 10, because the row A12..E12 is empty. If you use a larger row number on your database, you can add more records to your database without having to modify the argument from time to time. Display: _______ The following shows cells T1..W7. T U V W ________________________________________ 1 2 Last Name: Last Name 3 4 Date Hired: Age: Date Hired Age 5 6 Salary: Sex: Salary Sex 7 DB_INPUT scans the display area from left to right and top to bottom. If it finds a cell is non-empty, it will match the cell to the field defines in the relation list. In relation list _____________ the above example, Last Name maps to field 1, Date Hired to Last Name Date Hired field 2, Age to field 3, Salary to field 5 and Sex to field Age Salary Sex 4. The column widths of U and W confine the line editor U W D 10 SHEET -- Database Part By Chor-ming Lung November 1, 1989 widths. Query: _____ L2..P10 is our criteria range. Here is the list of our criteria range: L M N O P 2 L:Name Date HireAge Sex Salary 3 >50 m 4 f >40000 NOTE: NOTE The query range is L2..P10, DB_INPUT eliminates empty rows from the query range to create the actual criteria range for query. Relation list: _____________ The relation list helps DB_INPUT users to create free forms easily. You can design your input form in an order different from the fields defined on the database. DB_INPUT will use the minimal number between non-empty cells in display and relation list. For example, if you have 5 non- empty cells in your display and 6 numbers in your relation list, then DB_INPUT takes the first 5 as your relation list. If you have 10 non-empty cells in your display and 5 numbers in you relation list, then DB_INPUT scans only the first 5 non-empty cells from the display. The rest cells will be displayed but have not effect in editing. DB_INPUT entry: DB_INPUT entry ______________ DB_INPUT accepts the following formats of data: - text string. - date number. The format of the date number is defined in date string Form. It is Defaults dialog (to get the Form Defaults Default dialog, you should select menu item Defaults Default Defaults under menu title Sheet). NOTE: the function DATE is Sheet NOTE hard-coded to read date in the sequence of month, day, and year. If you change the date string Date1, Date2 or Date1 Date2 Date3, they just change the appearance of your Date3 spreadsheet display. They will not change the input sequence of the DATE function. That is why some users from England saying that the new date format does not work. However, DB_INPUT reads date in the sequence date string Form defined. So, if you change the date string Form Form to dd-mm-yy, then Oct 26th, 1989 should be entered Form 26-10-89. 26-10-89 - numeric number. DB_INPUT will not accept formula at this moment, but you can enter formula in your query forms. NOTE1: NOTE1 the criteria uses the standard method to calculate result. If you want to find the persons who are hired before March 1st,83. You must enter the formula