home *** CD-ROM | disk | FTP | other *** search
/ Software Du Jour / SoftwareDuJour.iso / BUSINESS / DBASE / CLIPUDF.ARC / LAST_FLD.PRG < prev    next >
Encoding:
Text File  |  1986-02-04  |  1.4 KB  |  45 lines

  1. * Function ..... LAST_FIELD()
  2. * Author ....... Steve Straley
  3. * Date ......... August 21, 1985
  4. * Syntax ....... LAST_FIELD(character string)
  5. * Parameters ... Filename
  6. * Returns ...... <numeric value>
  7. * Notes ........ This function will return the number of fields in the
  8. *                given database.  This function does a binary search to
  9. *                determine the position of the last field in the database.
  10.  
  11. FUNCTION LAST_FIELD
  12.  
  13. Parameters Filename
  14.  
  15. Use &Filename
  16.  
  17. first  = 1
  18. last   = 1024
  19. middle = INT(last/2)
  20.  
  21. DO WHILE first <> last
  22.    ******************************
  23.    * check to see what is the length of the field at position middle.
  24.    * IF the value is 0, then there is no field at position middle and
  25.    * make the value of last equal to middle.
  26.    * ELSE, there is a value at position middle and then make the value
  27.    * of first equal to middle.
  28.    * Once this is done, then re-calculate the value of middle based on
  29.    * the new values of first and last
  30.    ******************************
  31.    IF LEN(FIELDNAME(middle)) = 0
  32.       last = middle
  33.    ELSE
  34.       first = middle
  35.    ENDIF
  36.    middle = first + INT((last-first)/2)
  37.    IF LEN(FIELDNAME(middle)) > 0 .AND. LEN(FIELDNAME(middle + 1)) = 0
  38.       last = middle
  39.       first = middle
  40.    ENDIF
  41. ENDDO
  42.  
  43.  
  44. RETURN(last)
  45.