home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a012 / 1.ddi / CHAP25.EXE / CHP2510.PRG < prev    next >
Encoding:
Text File  |  1991-06-12  |  1.8 KB  |  71 lines

  1. /*
  2.    Listing 25.10. Record positioning function for browsing
  3.                   with a WHILE condition.
  4.    Author: Craig Yellick
  5.    Excerpted from "Clipper 5: A Developer's Guide"
  6.    Copyright (c) 1991 M&T Books
  7.                       501 Galveston Drive
  8.                       Redwood City, CA 94063-4728
  9.                       (415) 366-3600
  10. */
  11.  
  12. function PosWhile(how, firstKey, condition, howMany)
  13. /*
  14.    General-purpose record positioning function, called by
  15.    TBrowse goTop, goBottom and skip blocks. Returns number
  16.    of records actually skipped if in "skip" mode.
  17.  
  18.    Note: It's assumed the database is already positioned at
  19.    the first matching key (for example, after a SEEK).
  20. */
  21. //  Assume no movement was possible
  22. local actual := 0
  23. local softStat
  24.  
  25.   do case
  26.   case how = "top"
  27.     seek firstKey
  28.  
  29.   case how = "bottom"
  30.     softStat := set(_SET_SOFTSEEK, .t.)
  31.     seek (left(firstKey, len(firstKey) -1) +chr(255))
  32.     skip -1
  33.     set(_SET_SOFTSEEK, softStat)
  34.  
  35.   case how = "skip"
  36.     do case
  37.     //  Moving backwards
  38.     case howMany < 0
  39.       do while (actual > howMany) .and. (.not. bof()) ;
  40.                .and. eval(condition, firstKey)
  41.       skip -1
  42.       if (.not. bof()) .and. eval(condition, firstKey)
  43.         actual--
  44.       endif
  45.     enddo
  46.     if (.not. eval(condition, firstKey))
  47.       skip +1
  48.     endif
  49.  
  50.     //  Moving forwards
  51.     case howMany > 0
  52.       do while (actual < howMany) .and. (.not. eof()) ;
  53.                .and. eval(condition, firstKey)
  54.       skip +1
  55.       if (.not. eof()) .and. eval(condition, firstKey)
  56.         actual++
  57.       endif
  58.     enddo
  59.     if eof() .or. (.not. eval(condition, firstKey))
  60.       skip -1
  61.     endif
  62.  
  63.     //  No movement requested, re-read current record
  64.     otherwise
  65.       skip 0
  66.     endcase
  67.   endcase
  68. return actual
  69.  
  70. // end of file CHP2510.PRG
  71.