home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 7 / POWERCD7.ISO / prgmming / clipper / gt_gobot.prg < prev    next >
Text File  |  1993-10-14  |  2KB  |  108 lines

  1. /*
  2.     File......: GT_GoBottom.prg
  3.     Author....: Martin Bryant
  4.     BBS.......: The Dark Knight Returns
  5.     Net/Node..: 050/069
  6.     User Name.: Martin Bryant
  7.     Date......: 11/02/93
  8.     Revision..: 1.0
  9.  
  10.     This is an original work by Martin Bryant and is placed
  11.     in the public domain.
  12.  
  13.     Modification history:
  14.     ---------------------
  15.  
  16.     Rev 1.0 11/02/93
  17.     PD Revision.
  18. */
  19.  
  20. /*  $DOC$
  21.  *  $FUNCNAME$
  22.  *      GT_GOBOTTOM()
  23.  *  $CATEGORY$
  24.  *      General
  25.  *  $ONELINER$
  26.  *      Move the filepointer to the last record
  27.  *  $SYNTAX$
  28.  *      GT_GoBottom([<bWhile>],[<bFor>],[<bFind>]) -> NIL
  29.  *  $ARGUMENTS$
  30.  *      <bWhile> Code block giving a while clause.
  31.  *
  32.  *      <bFor> Code block giving a for clause.
  33.  *
  34.  *      <bFind> Code block giving a value to compare against
  35.  *      the index. Acts as a form of while clause.
  36.  *  $RETURNS$
  37.  *      NIL
  38.  *  $DESCRIPTION$
  39.  *      Reposition the filepointer to the last record given
  40.  *      a for/while clause.
  41.  *  $EXAMPLES$
  42.  *  $SEEALSO$
  43.  *
  44.  *  $INCLUDE$
  45.  *
  46.  *  $END$
  47.  */
  48.  
  49. #include "GT_LIB.ch"
  50.  
  51. FUNCTION GT_GoBottom(bWhile,bFor,bFind)
  52.  
  53. LOCAL cLast := ''
  54. LOCAL cData := ''
  55. LOCAL nLength := ''
  56. LOCAL lFault := .T.
  57.  
  58. Default bWhile to { | | .NOT. EOF() }
  59. Default bFor to { | | .T. }
  60. Default bFind to NIL
  61.  
  62. IF bFind = NIL
  63.  
  64.     // Can't find directly
  65.     DBGOTO(LASTREC()+1)
  66.  
  67. ELSE
  68.  
  69.     // Get value
  70.     cData := EVAL(bFind)
  71.     nLength := LEN(cData)
  72.  
  73.     // Increment value to bFind
  74.     cLast := CHR(ASC(SUBSTR(cData,nLength,1))+1)
  75.     cLast := SUBSTR(cData,nLength-1,1) + cLast
  76.  
  77.     //  Find first item not legal
  78.     DBSEEK(cLast)
  79.  
  80. ENDIF
  81.  
  82. //  Should be last inwhile clause
  83. DBSKIP(-1)
  84.  
  85. //  Skip back till while and for OK
  86. DO WHILE EVAL(bWhile) .AND. .NOT. BOF()
  87.  
  88.     IF EVAL(bFor)
  89.  
  90.         lFault := .F.
  91.         EXIT
  92.  
  93.     ENDIF
  94.  
  95.     DBSKIP(-1)
  96.  
  97. ENDDO
  98.  
  99. //  OK?
  100. IF lFault
  101.     DBGOTO(LASTREC()+1)
  102. ENDIF
  103. /*
  104.     End of GT_GoBottom()
  105. */
  106. RETURN(NIL)
  107.  
  108.