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

  1. /*
  2.  * File......: MOVEPOS.PRG
  3.  * Author....: Martin Colloby
  4.  * BBS.......: The Dark Knight Returns
  5.  * Net/Node..: 050/069
  6.  * User Name.: Martin Colloby
  7.  * Date......: 18/4/93
  8.  * Revision..: 1.0
  9.  *
  10.  * This is an original work by Martin Colloby and is placed in the public
  11.  * domain.
  12.  *
  13.  * Modification history:
  14.  * ---------------------
  15.  *
  16.  * $Log$
  17.  *
  18.  */
  19.  
  20.  
  21. /*  $DOC$
  22.  *  $FUNCNAME$
  23.  *      GT_MOVEPOS()
  24.  *  $CATEGORY$
  25.  *      General
  26.  *  $ONELINER$
  27.  *      General purpose TBrowse skip function
  28.  *  $SYNTAX$
  29.  *      GT_MovePos( cMode , cFirstKey , bCondition , nNumber , lEmpty )
  30.  *  $ARGUMENTS$
  31.  *      cMode      - Mode in which to move
  32.  *      cFirstKey  - Key to search for
  33.  *      bCondition - Conditional code block
  34.  *      nNumber    - Number of records to skip
  35.  *      lEmpty     - If .T., position pointer at LASTREC() + 1
  36.  *  $RETURNS$
  37.  *      The number of elements skipped
  38.  *  $DESCRIPTION$
  39.  *      A general purpose table based TBrowse skip routine.
  40.  *  $EXAMPLES$
  41.  *
  42.  *  $SEEALSO$
  43.  *
  44.  *  $INCLUDE$
  45.  *      GT_LIB.CH
  46.  *  $END$
  47.  */
  48.  
  49. *
  50. #include "GT_lib.ch"
  51.  
  52. FUNCTION GT_MovePos( cMode , cFirstKey , bCondition , nNumber , lEmpty )
  53.  
  54. /*****************************************************************************
  55.  Purpose - Generic record positioning function for TBrowses
  56.  Returns - None
  57.  Author  - Martin Colloby
  58.  Created - 20/07/92
  59. ******************************************************************************
  60.  Parameters - cMode      - Mode in which to move
  61.               cFirstKey  - Key to search for
  62.               bCondition - Conditional code block
  63.               nNumber    - Number of records to skip
  64.               lEmpty     - If .T., position pointer at LASTREC() + 1
  65.  Privates   - None
  66.  Locals     - None
  67.  Externals  - None
  68. ******************************************************************************
  69.  Notes - Record positioning function, called by TBrowse goTop, goBottom,
  70.          and skip blocks. Returns number of records actually skipped if in
  71.          "Skip" mode.
  72.  
  73.          N.B. It's assumed the database is already positioned at the first
  74.               matching key (for example, after a SEEK).
  75. *****************************************************************************/
  76.  
  77. * Assume no movement was possible
  78. LOCAL nActual    := 0
  79. LOCAL lSoftStat  := .F.
  80. LOCAL cCurYear   := ""
  81. LOCAL cCurNumber := ""
  82.  
  83. DEFAULT lEmpty TO .F.
  84.  
  85. DO CASE
  86.     CASE cMode == "First"
  87.         SEEK cFirstKey
  88.  
  89.     CASE cMode == "Last"
  90.         lSoftStat := SET( _SET_SOFTSEEK , .T. )
  91.         SEEK ( LEFT( cFirstKey, LEN( cFirstkey ) - 1 ) ;
  92.               + CHR( ( ASC( RIGHT( cFirstKey, 1 ) ) + 1 ) ) )
  93.         SKIP -1
  94.         SET( _SET_SOFTSEEK , lSoftStat )
  95.  
  96.     CASE cMode == "Skip"
  97.         IF lEmpty
  98.             GOTO LASTREC() + 1
  99.             RETURN 0
  100.         ENDIF
  101.  
  102.         DO CASE
  103.             *  Moving backwards
  104.             CASE nNumber < 0
  105.                 DO WHILE ( nActual > nNumber ) .AND. !BOF() ;
  106.                                                .AND. EVAL( bCondition , cFirstKey )
  107.                     SKIP -1
  108.                     IF !BOF() .AND. EVAL( bCondition , cFirstKey )
  109.                         nActual--
  110.                     ENDIF
  111.                 ENDDO
  112.                 IF !EVAL( bCondition , cFirstKey )
  113.                     SKIP +1
  114.                 ENDIF
  115.  
  116.             *  Moving forwards
  117.             CASE nNumber > 0
  118.                 DO WHILE ( nActual < nNumber ) .AND. !EOF() ;
  119.                                                .AND. EVAL( bCondition , cFirstKey )
  120.                     SKIP +1
  121.                     IF !EOF() .AND. EVAL( bCondition , cFirstKey )
  122.                         nActual++
  123.                     ENDIF
  124.                 ENDDO
  125.                 IF EOF() .OR. !EVAL( bCondition , cFirstKey )
  126.                     SKIP -1
  127.                 ENDIF
  128.  
  129.             *  No movement requested, re-read current record
  130.             OTHERWISE
  131.                 SKIP 0
  132.  
  133.         ENDCASE
  134.  
  135. ENDCASE
  136.  
  137. RETURN nActual
  138. *
  139.