Go, GoTo, Skip
These are two of the original commands in the Xbase language, useful for jumping to specific records while working interactively, but other commands have replaced their utility within programs in most cases.
Usage |
[ GO | GOTO ] [ RECORD ] nRecordNumber | TOP | BOTTOM [ IN nWorkArea | cAlias ] |
&cRecNowon't make sense to many people. The keywords TOP and BOTTOM go to the first and last records, respectively, in the current index order, or in the natural record order if the table doesn't have a current active index, obeying any filter in place. The IN clause allows you to move the record pointer in another area by specifying either the work area number or the alias of the table open in that area.GO is not Rushmore-optimizable. Rather than using GO TOP or BOTTOM, use LOCATE instead—see the trick to it in "Faster Than a Speeding Bullet."Many of us have used the trick of storing the record number to a memory variable, doing some processing, and then restoring the record pointer to its original position with GO. This still works fine in Visual FoxPro, but a common extension of the trick may not. If the record pointer was at the "phantom record," beyond the last true record in the file, issuing GO (nRecNo) would result in a "Record is out of range" error, so the trick was to store –1 as the record number if the record pointer was at the end of the file, and place the record pointer back there if so. This is a clever trick, but beware: If you are working on tables with table buffering enabled, Visual FoxPro actually does use negative record numbers for uncommitted buffered records. Consider using 0 (zero) instead.
VFP 7 Service Pack 1 fixes a bug that crashes VFP: using GOTO to move to a buffered record in a view for which you've created an index. That's a fairly obscure situation—in fact, we only heard of this when we saw it on the list of bugs fixed in the service pack. |
Example |
nRecNo() = IIF( EOF(), 0, RecNo() ) * Do your processing here CASE RECCOUNT() = 0 * DO NOTHING CASE nRecNo = 0 GO BOTTOM SKIP OTHERWISE GO (nRecno) ENDCASE |
Usage |
SKIP [ nHowMany ] [ IN nWorkArea | cAlias ] |
Example |
SKIP -2 && Go back two records |
See Also |