The select statement scans the database and selects records that match a formula you provide. But what if the formula fails to match any records? Eeek! Panorama always requires that at least one record be selected at all times, it never allows the entire database to be invisible. If none of the records in the database match the formula, Panorama will automatically select all records (if you want to leave the previous selection intact, use the safeselect statement). Of course this could be a problem if the following statements are expecting a particular subset of the database to be selected and instead all records are selected.
Fortunately, Panorama normally handles this situation for you automatically so that your code works correctly in most situations. Panorama keeps track of the fact that there should be no records selected, and it will skip any statement that modifies the database, including formulafill, sequence, propagate, unpropagate, etc. Panorama will continue skipping these statements until it comes to a selectall statement or another select statement, or until the procedure is finished.
For example, this program will fill the InvoiceAge field with the age of every outstanding invoice in the database. It will modify the age for records that have been shipped but not fully paid. If a record hasn’t shipped yet, it will be skipped, and records that have been paid will also be skipped.
select sizeof(ShipDate)≠0 and Balance>0
field InvoiceAge
formulafill today()-ShipDate
selectall
But what if there are no outstanding invoices? In that case, the code above won’t do anything. The select statement won’t match any records, so the formulafill statement will be skipped.
Panorama’s automatic statement skipping for empty subsets should work fine for most applications. As a programmer, however, you have the choice of overriding this statement skipping and programming your own solution to the empty subset condition.
To test for an empty subset, use the info(“empty”) function. Here is a modified version of the previous example. It works exactly the same, except that it will display a message if there are no outstanding invoices.
select sizeof(ShipDate)≠0 and Balance>0
if info("empty")
message "No outstanding invoices!"
else
field InvoiceAge
formulafill today()-ShipDate
selectall
endif
Panorama also has a special ifselect statement that can also be used to customize what happens after an empty selection. You may find this code easier to follow.
ifselect sizeof(ShipDate)≠0 and Balance>0
field InvoiceAge
formulafill today()-ShipDate
selectall
else
message "No outstanding invoices!"
endif
Remember, this sort of special logic is only necessary if you want to perform some special handling of empty subsets. Normally, Panorama will handle the empty subset just fine on its own by skipping the statements until the selected subset changes.
See Also
- checkemptyselection -- notifies the user if a selection failed, and reverts to the previous selection.
- Date Search Options -- searching dates within a database.
- Favorite Searches -- saving and recalling favorite searches.
- find -- locates the first visible record in the active database for which the specified condition is true.
- Find & Replace Dialog -- finding and replacing a word or phrase (with an option to use a regular expression).
- Find/Select Dialog -- using a dialog to search for specific data.
- findabove -- locates the next previous record (above the current record) in the active database for which the specified condition is true.
- findbackwards -- locates the last visible record in the active database for which the specified condition is true.
- findbelow -- locates the next visible record (below the current record) in the active database for which the specified condition is true.
- findid -- locates a record in the active database by its ID number (see info("serverrecordid").
- findnth -- finds the nth (2nd, 3rd, 4th, etc.) record that matches a true-false test.
- findselect -- opens the standard *Find/Select* dialog.
- findselectdialog -- opens the standard *Find/Select* dialog.
- Formula Search -- searching with a formula.
- ifselect -- combines the select and if info("empty") operations into a single statement.
- info("empty") -- returns true or false depending on the result of the last select operation. If no records were selected the function will return true, otherwise it will return false.
- info("found") -- returns true or false depending on whether the last *find* or *next* statement was successful.
- info("selectduplicatesortwarning") -- works with the selectduplicatesnowarning statement to ascertain whether or not the database was sorted correctly when last search for duplicates was performed.
- nextmatch -- locates the next visible record in the active database for which the condition specified in the most recent Find statement is true.
- Numeric Search Options -- searching numbers within a database.
- pleaseselectall -- makes sure that all records are selected.
- previousmatch -- locates the previous (closer to the top) visible record in the active database for which the condition specified in the most recent Find statement is true.
- Record Search Options -- searching via record attributes.
- Refining a Selection -- selecting a subset or superset of a previous selection."
- removeselected -- deletes all selected records from the database.
- removeunselected -- deletes all unselected records from the database.
- safeselect -- makes visible only those records for the active database for which the specified condition is true. If no records match, the previous selection is retained.
- safeselectwithin -- makes visible only those previously selected records in the active database for which the specified condition is true. If no records match, the previous selection is retained.
- search( -- searches through an item of text looking for a character, word or phrase. If it finds an exact match (including upper/lower case) with the character, word or phrase, it returns its position within the text item. If it does not find the character, word or phrase, it returns zero.
- searchanycase( -- searches through an item of text looking for a character, word or phrase. If it finds a match (upper/lower case may be different) with the character, word or phrase, it returns its position within the text item. If it does not find the character, word or phrase, it returns zero.
- Searching -- searching a database to find or select information.
- select -- makes visible only those records for the active database for which the specified condition is true.
- Select Duplicates Dialog -- opens the standard *Select Duplicates* dialog sheet.
- selectadditional -- adds unselected records to a previously selected group if they match the true-false test.
- selectall -- makes every record in the database visible.
- selectduplicates -- selects records containing duplicate information in the database.
- selectduplicatesnowarning -- selects records containing duplicate information in the database.
- Selecting with the Context Menu -- searching for information related to the current cell.
- selectreverse -- makes every visible record invisible, and every invisible record visible.
- selectwithin -- uses a Boolean formula to exclude records from a previously selected group.
- Text Search Options -- searching text within a database.
History
10.0 | No Change | Carried over from Panorama 6.0. |