home *** CD-ROM | disk | FTP | other *** search
- /*
- Listing 25.7. RecPosition(), a general-purpose record
- positioning and status function.
- Author: Craig Yellick
- Excerpted from "Clipper 5: A Developer's Guide"
- Copyright (c) 1991 M&T Books
- 501 Galveston Drive
- Redwood City, CA 94063-4728
- (415) 366-3600
- */
-
- function RecPosition(how, howMany)
- /*
- General-purpose record positioning function, called by TBrowse
- goTop, goBottom and skip blocks. Returns number of records
- actually skipped if in "skip" mode.
-
- Also can be called with no parameters to get record position
- within database, independent of presence of index.
- */
- // Assume no movement was possible
- local actual := 0
-
- static where := 1
-
- do case
- case how = "top"
- where := 1
- goto top
-
- case how = "bottom"
- where := lastrec()
- goto bottom
-
- case how = "skip"
- do case
- // Moving backwards
- case howMany < 0
- do while (actual > howMany) .and. (.not. bof())
- skip -1
- if .not. bof()
- actual--
- endif
- enddo
-
- // Moving forwards
- case howMany > 0
- do while (actual < howMany) .and. (.not. eof())
- skip +1
- if .not. eof()
- actual++
- endif
- enddo
- if eof()
- skip -1
- endif
-
- // No movement requested, re-read current record
- otherwise
- skip 0
- endcase
-
- // No parameters passed, return current position.
- otherwise
- return where
- endcase
-
- // Update position tracker and prevent boundary wrap.
- where += actual
- where := min(max(where, 1), lastrec())
-
- return actual
-
- // end of file CHP2507.PRG
-