home *** CD-ROM | disk | FTP | other *** search
- /*
- Listing 25.10. Record positioning function for browsing
- with a WHILE condition.
- 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 PosWhile(how, firstKey, condition, howMany)
- /*
- General-purpose record positioning function, called by
- TBrowse goTop, goBottom and skip blocks. Returns number
- of records actually skipped if in "skip" mode.
-
- Note: It's assumed the database is already positioned at
- the first matching key (for example, after a SEEK).
- */
- // Assume no movement was possible
- local actual := 0
- local softStat
-
- do case
- case how = "top"
- seek firstKey
-
- case how = "bottom"
- softStat := set(_SET_SOFTSEEK, .t.)
- seek (left(firstKey, len(firstKey) -1) +chr(255))
- skip -1
- set(_SET_SOFTSEEK, softStat)
-
- case how = "skip"
- do case
- // Moving backwards
- case howMany < 0
- do while (actual > howMany) .and. (.not. bof()) ;
- .and. eval(condition, firstKey)
- skip -1
- if (.not. bof()) .and. eval(condition, firstKey)
- actual--
- endif
- enddo
- if (.not. eval(condition, firstKey))
- skip +1
- endif
-
- // Moving forwards
- case howMany > 0
- do while (actual < howMany) .and. (.not. eof()) ;
- .and. eval(condition, firstKey)
- skip +1
- if (.not. eof()) .and. eval(condition, firstKey)
- actual++
- endif
- enddo
- if eof() .or. (.not. eval(condition, firstKey))
- skip -1
- endif
-
- // No movement requested, re-read current record
- otherwise
- skip 0
- endcase
- endcase
- return actual
-
- // end of file CHP2510.PRG
-