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

  1. /*
  2.  * File......: ARRASKIP.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_ARRAYSKIP()
  24.  *  $CATEGORY$
  25.  *      General
  26.  *  $ONELINER$
  27.  *      General purpose TBrowse skip routine for arrays
  28.  *  $SYNTAX$
  29.  *      GT_ArraySkip( nArrayLen , nNumber )
  30.  *  $ARGUMENTS$
  31.  *      aArrayLen - Length of the array
  32.  *      nNumber   - Number of positions to skip
  33.  *  $RETURNS$
  34.  *      Number of positions skipped
  35.  *  $DESCRIPTION$
  36.  *      This function acts as a general purpose skip utility for array based
  37.  *      TBrowses.
  38.  *  $EXAMPLES$
  39.  *      Skip forward one record in an array of ten elements :
  40.  *
  41.  *          nSkipped := GT_ArraySkip( 10 , 1 )
  42.  *  $SEEALSO$
  43.  *
  44.  *  $INCLUDE$
  45.  *      GT_LIB.CH
  46.  *  $END$
  47.  */
  48.  
  49. *
  50. #include "GT_lib.ch"
  51.  
  52. MEMVAR nRecord
  53.  
  54. FUNCTION GT_ArraySkip( nArrayLen , nNumber )
  55.  
  56. /*****************************************************************************
  57.  Purpose - General purpose array skipping function intended for
  58.            use with TBrowse b:SkipBlocks.
  59.  Returns - None
  60.  Author  - Log
  61.  Created - 15/01/93
  62. ******************************************************************************
  63.  Parameters - None
  64.  Privates   - None
  65.  Locals     - None
  66.  Externals  - None
  67. *****************************************************************************/
  68.  
  69. LOCAL nActual := 0
  70.  
  71. IF nNumber >= 0                             //Moving forward ?
  72.     IF ( nRecord + nNumber ) > nArrayLen    //Can't go that far !
  73.         nActual := nArrayLen - nRecord      //Actual is whatever is left
  74.         nRecord := nArrayLen                //Put pointer at end
  75.     ELSE                                    //Can move the whole distance
  76.         nActual := nNumber                  //Actual is number requested
  77.         nRecord += nNumber                  //Move pointer forward
  78.     ENDIF
  79. ELSE                                        //Moving backward ?
  80.     IF ( nRecord + nNumber ) < 1            //Can't go that far !
  81.         nActual := 1 - nRecord              //Actual is whatever was left
  82.         nRecord := 1                        //Put pointer at top
  83.     ELSE                                    //Can move the whole distance
  84.         nActual := nNumber                  //Actual is number requested
  85.         nRecord += nNumber                  //Move pointer backwards
  86.     ENDIF
  87. ENDIF
  88.  
  89. RETURN nActual
  90. *
  91.