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

  1. /*
  2.    Listing 25.7. RecPosition(), a general-purpose record
  3.                  positioning and status function.
  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 RecPosition(how, howMany)
  13. /*
  14.    General-purpose record positioning function, called by TBrowse
  15.    goTop, goBottom and skip blocks. Returns number of records
  16.    actually skipped if in "skip" mode.
  17.  
  18.    Also can be called with no parameters to get record position
  19.    within database, independent of presence of index.
  20. */
  21. //  Assume no movement was possible
  22. local actual := 0
  23.  
  24. static where := 1
  25.  
  26.   do case
  27.   case how = "top"
  28.     where := 1
  29.     goto top
  30.  
  31.   case how = "bottom"
  32.     where := lastrec()
  33.     goto bottom
  34.  
  35.   case how = "skip"
  36.     do case
  37.     //  Moving backwards
  38.     case howMany < 0
  39.       do while (actual > howMany) .and. (.not. bof())
  40.         skip -1
  41.         if .not. bof()
  42.           actual--
  43.         endif
  44.       enddo
  45.  
  46.     //  Moving forwards
  47.     case howMany > 0
  48.       do while (actual < howMany) .and. (.not. eof())
  49.         skip +1
  50.         if .not. eof()
  51.           actual++
  52.         endif
  53.       enddo
  54.       if eof()
  55.         skip -1
  56.       endif
  57.  
  58.     //  No movement requested, re-read current record
  59.     otherwise
  60.       skip 0
  61.     endcase
  62.  
  63.   //  No parameters passed, return current position.
  64.   otherwise
  65.     return where
  66.   endcase
  67.  
  68.   //  Update position tracker and prevent boundary wrap.
  69.   where += actual
  70.   where := min(max(where, 1), lastrec())
  71.  
  72. return actual
  73.  
  74. // end of file CHP2507.PRG
  75.