Eof Function | |
Determine when end-of-file is encountered.
Namespace:
XSharp.RT
Assembly:
XSharp.RT (in XSharp.RT.dll) Version: 2.19
Syntax Request Example
View SourceReturn Value
Type:
Logic
TRUE when an attempt is made to move the record pointer beyond the last logical record in a database file or if the database file contains no records; otherwise, FALSE.
If there is no database file open in the work area, EOF() returns TRUE.
Remarks
EOF() is a database function used to test for an end-of-file boundary condition when the record pointer is
moving forward through a database file.
Any command that can move the record pointer can set EOF().
The most typical application is as a part of the lCondition argument of a DO WHILE construct that
sequentially processes records in a database file. Here lCondition would include a test for .NOT.
EOF(), forcing the DO WHILE loop to terminate when EOF() returns TRUE.
EOF() and Found() are often used interchangeably to test whether a SEEK, FIND, or LOCATE command failed.
With these commands, however, Found() is preferred.
When EOF() returns TRUE, the record pointer is positioned at LastRec() + 1 regardless of
whether there is an active filter setting or SetDeleted() is TRUE.
Further attempts to move the record pointer forward return the same result without error.
Once EOF() is set to TRUE, it retains its value until there is another attempt to move the record pointer.
By default, this function operates on the currently selected work area.
It can be made to operate on an unselected work area by specifying
it within an aliased expression or by calling the overload that accepts a workarea
parameter (a workarea number or alias ).
Examples
This example demonstrates EOF() by deliberately moving the record pointer beyond the last record:
1USE sales
2DBGoBottom()
3QOut(EOF())
4SKIP
5QOut(EOF())
This example uses aliased expressions to query the value of EOF() in unselected work areas:
1USE sales NEW
2USE customer NEW
3QOut(Sales->EOF())
4QOut(Customer->EOF())
This example illustrates how EOF() can be used as part of a condition for sequential database file operations:
1USE sales INDEX custnum NEW
2DO WHILE !(Sales->EOF())
3 nOldCust := Sales->CustNum
4 nTotalAmount := 0
5 DO WHILE nOldCust = Sales->CustNum .AND. ;
6 !(Sales->EOF()
7 QOut(Sales->CustNum, ;
8 Sales->Description, ;
9 Sales->SaleAmount)
10 nTotalAmount += Sales->SaleAmount
11 SKIP
12 ENDDO
13 QOut("Total amount: ", nTotalAmount)
14ENDDO
You could have written the EOF check in the code above with an alias parameter to EOF() as well:
1DO WHILE !EOF("Sales")
2 .
3 .
4ENDDO
See Also