Find Percentage (45)
The Find Percentage operation (B_GET_PERCENT) is one of two Btrieve API operations that window-oriented applications can use to implement scroll bars. The other is the Get By Percentage operation (44). Find Percentage finds the approximate position of a record either relative to a key path or as the record’s physical location within the file. The position is expressed as a percentage value. See the “Result” section for a definition of the range of percentage values.
Parameters
 
*Note: When seeking the percentage relative to a key path, Find Percentage does not require an input value for the Data Buffer parameter. When seeking the percentage as relative to a record’s physical location within the file, Find Percentage does not require an input value for the Key Buffer parameter.
Prerequisites
Procedure
1
2
3
4
5
6
a.
b.
Details
The Find Percentage operation is provided specifically to support scroll bar implementation. Because many factors affect the accuracy of this operation—that is, whether the returned percentage value accurately reflects the position of the record or key value—you should not rely on the accuracy of this operation for other purposes.
To optimize the Find Percentage operation, the transactional interface assumes that a file has an even distribution of records among the data pages and keys among the index pages. However, distribution can be affected by the following situations:
Granularity
The granularity setting is optional and allows you to choose the factor by which the percentage is measured. In releases prior to Pervasive PSQL 9, this value was always 10,000.
If you want to specify the granularity, follow these steps:
1
2
3
For example if you want to get the 100th record from a file that contains 365 records, you can use FindPercentage with 100 as the percentage, and 365 as the granularity.
Result
If the Find Percentage operation is successful, the transactional interface returns the relative position of the specified key value or record to the Data Buffer. This position is expressed as a percentage of the offset into the key path or file and is a value in the range of 0 (0 percent) through 10,000 (100.00 percent). Note this is not the physical or logical position.
The percentage value is returned as a 2-byte integer in low-byte, high-byte order. For example:
The transactional interface also returns a Data Buffer Length of 4 if the operation is successful.
If the Find Percentage operation is unsuccessful, the transactional interface returns one of the following status codes:
Positioning
The Find Percentage operation does not change any currency information.