- Generic search/Exact-match search
- Search performed on a key item or on a non-key item
- Performing a search on a composite key
- Search and filter
- Search on an array item
- Browsing the records corresponding to a condition
- Exact-match search in Access
- Locks
- Optimizing the browse operations
HReadSeekLast (Function) In french: HLitRechercheDernier
Not available with this kind of connection
// Find the last record for which // the CUSTOMER name is MOORE HReadSeekLast(CUSTOMER, NAME, "MOORE")
// Find all the customers whose turnover is less than a specific value HReadSeekLast(CUSTOMER, Turnover, X) WHILE NOT HOut(CUSTOMER) AddCustomerList() HReadPrevious(CUSTOMER, Turnover) END
Syntax
<Result> = HReadSeekLast(<Data file> , <Item> , <Sought value> [, <Options>])
<Result>: Boolean - True if the record was found (corresponds to the value of HFound).
- False if a problem occurred. This problem can be caused by:
- a positioning problem (empty data file, etc.): HFound returns False and HError returns 0.
- an error: HError returns an integer other than 0. HErrorInfo returns more details.
<Data file>: Character string (with or without quotes) Name of data file, HFSQL view or query used. <Item>: Character string (with or without quotes) Name of item on which the search will be performed. This item can be a search key or not.
<Sought value>: Type corresponding to the value Value of sought item. <Options>: Optional constant (or combination of constants) Used to configure:- the lock mode applied to the sought record.
- the type of search performed.
| | hLockReadWrite | Lock in read/write: the record currently read cannot be read or modified by another application. The lock mode is ignored if a query is used.
| hLockWrite | Lock in write mode: the record currently read can be read by another application but it cannot be modified by another application. The lock mode is ignored if a query is used.
| hLockNo | No lock (even if HStartLock was called): the record can be read or modified by another application during the reading.
| Versions 17 and laterhForwardOnly New in version 17hForwardOnly hForwardOnly | | hGeneric | Generic search (see the Notes) An exact-match search is performed by default (constant not specified). | hLimitParsing | The browse will stop as soon as the last sought value is found. The current record will correspond to this last record found. HFound will return False and HOut will return True. This constant is used to optimize the search speed in Client/Server mode. | hKeepFilter | The filter implemented by HFilter will be taken into account, even if the search key is not optimized for the filter. Reminder: HFilter returns the search key optimized for the filter. Caution: in this case, poor performance may occur on huge data files. By default, the browse performed after HReadSeekLast ignores the filter. | hNoRefresh | |
Remarks Generic search/Exact-match search - Generic search (mainly on the Character String items): Finds all records starting with the specified value.
For example: When a generic search is performed on "Martin" (for the NAME item), all records whose Name item starts with "Martin" will correspond to the search. Therefore, the record containing "Martinez" will correspond to the search (HFound returns True). Remark: For backward compatibility with version 5.5, the generic search of an empty string ("") is equivalent to the use of HReadLast. - Exact-match search: Finds all records that exactly correspond to the specified value.
For example: When an exact-match search is performed on "Martin" (for the NAME item), HFound returns True for the records whose item exactly matches "Martin". - Examples of searches performed on CUSTOMER file sorted by name:
 | | | | | | Sought value | Options | HReadSeekLast positions on the record. | HFound returns | HOut returns | Explanations | Davon | | 6 | True | False | Davon exists. The beginning of data file was not reached yet. | Davo | | 5 | False | False | Davo does not exist. Positioning on the first lower value (Davis). The beginning of data file was not reached yet. | Davi | hGeneric | 5 | True | False | Davi does not exist but the search is a generic search and Davis is found (among other ones). The beginning of data file was not reached yet. | Davi | | The record was not found (no move). | False | False | Davi does not exist. The beginning of data file was not reached yet. | Bernard | | The record was not found (no move). | False | True | Bernard does not exist. Positioning on the first lower value (this value does not exist): the beginning of data file was reached. |
Search performed on a key item or on a non-key item The search can be performed on a key item or a non-key item. If the search is performed on a key item: - the search is fast and the result is sorted.
- if the browse is continued by HReadPrevious, the next records will correspond to the values less than or equal to the sought value. In this case, HOut must be checked after each read operation to find out whether the beginning of the file has been reached.
If the search is performed on a non-key item: - the selected item will appear in red in the code editor and a warning will be displayed in the "Compilation error" pane.
Remark: The automatic completion proposes the key items only. - if the browse is continued by HReadPrevious, the next records will correspond to the values equal to the sought value.
Performing a search on a composite key Several methods can be used to perform a search on a composite key: 1. Using a list of values The following syntax is used to perform a search on a composite key:
HReadSeekLast(<File name>, <Name of composite key>, [<Search value of first element of composite key>, <Search value of first element of composite key>, ...])
Example:
// Find the record HReadSeekLast(CUSTOMER, LASTNAME_FIRSTNAME, ["MOORE","Vince"])
2. Using HBuildKeyValue Example:
bufSoughtVal is Buffer = HBuildKeyValue(CUSTOMER, LASTNAME_FIRSTNAME, sLastName, sFirstName) HReadSeekLast(CUSTOMER, LASTNAME_FIRSTNAME, bufSoughtVal) WHILE HFound(CUSTOMER) HDelete(CUSTOMER) HPrevious(CUSTOMER, LASTNAME_FIRSTNAME) END
3. Using HConvert To build the value of a composite key without using HBuildKeyValue, you must: - fill the text components on their entire size with Charact(0).
- convert the numeric components with HConvert.
Example:
MyCompositeKey = Complete(Customer.CustomerLastName, Dimension(Customer.LastName), Charact(0)) + ... Complete(Customer.FirstName, Dimension(Customer.FirstName), Charact(0))
Search and filter If a filter is enabled ( HFilter), the filter is taken into account by the search only if the key used is identical. To take this filter into account in the rest of browse (even if the search key is not optimized for the filter), use the hKeepFilter constant.
Search on an array item The search is performed on the first array element (element whose subscript is 1). To perform a search on the other array elements, use the filters or queries. Browsing the records corresponding to a condition In most cases, HReadSeekLast is used to position in the data file in order to perform a browse loop among the records corresponding to a condition. HReadNext and HReadPrevious are used to read the next and previous records corresponding to the condition. To ignore the search while going to the next or previous record, use one of the following functions:
This page is also available for…
|
|
|