home *** CD-ROM | disk | FTP | other *** search
- *****************
-
- FUNCTION Ftypecnt
-
- PARAMETERS _thefile, _thetype, _position, _fnumb
-
- * _thefile is the database file to look at
- * _thetype is the file type sought for
- * _position is a string, passed by reference, which will be
- * build in the function which will point to what
- * positions each field type is found.
-
- IF PCOUNT() < 2
- RETURN(-1)
- ENDIF
-
- IF PCOUNT() = 2
- IF TYPE("_thefile")+TYPE("_thetype") != "CC"
- RETURN(-1)
- ENDIF
- ELSE
- IF TYPE("_thefile")+TYPE("_thetype")+TYPE("_position") != "CCC"
- RETURN(-1)
- ENDIF
- ENDIF
-
- _fnumb = IF((TYPE("_fnumb") != "L"), .F., _fnumb)
-
- PRIVATE _location, _return, _f1, _header, _count, _fname, _ftype, ;
- _fwhy, _flen
-
- _location = 0
-
- _return = LTRIM(STR(SELECT()))
-
- IF !ISA_DBF(_thefile) && Not a dbf file... then don't
- RETURN(.F.) && proceed
- ENDIF
-
- SELECT 0
- USE (_thefile)
- _header = HEADER()
- USE
- SELECT &_return.
- _f1 = FOPEN(_thefile)
- FSEEK(_f1, 32, 0) && Past the basic header stuff
- _count = 0
- DO WHILE FSEEK(_f1, 0, 1) < (_header - 31)
- _fname = SPACE(11)
- _ftype = SPACE(1)
- _fwhy = SPACE(4)
- _flen = SPACE(1)
- _fdec = SPACE(1)
- FREAD(_f1, @_fname, 11)
- FREAD(_f1, @_ftype, 1)
- FREAD(_f1, @_fwhy, 4)
- FREAD(_f1, @_flen, 1)
- FREAD(_f1, @_fdec, 1)
- _location = _location + BIN2I(_flen)
- IF _ftype = UPPER(_thetype)
- IF PCOUNT() >= 3
- IF _fnumb
- _position = _position + "/" + LTRIM(STR(_count))
- ELSE
- _position = _position + "/" + LTRIM(STR(_location - 8))
- ENDIF
- ENDIF
- _count = _count + 1
- ENDIF
- FSEEK(_f1, 14, 1)
- ENDDO
- FCLOSE(_f1)
- IF PCOUNT() >= 3
- IF SUBSTR(_position, 1, 1) = "/"
- _position = SUBSTR(_position, 2)
- ENDIF
- ENDIF
- RETURN(_count)
-
- * End of File
-