*--- ****Procedure CountRec ****This procedure counts the no of header recs and data recs in * a flat file ************************************************************ **** DataBase SECTION **** ****DataBases Used * None ****DataBases Created * None ************************************************************ **** Files SECTION **** ****Files Used * A flat file of the type generated by viking ****Files Created * None ************************************************************ **** VARIABLES SECTION **** ****Parameters GLOBAL ****Parameters pased to procedure * - Path to the flat file * - Variable to hold the no of Header recs counted * - Variable to hold the no of data recs counted * - Logical variable to set true if the file hase been looked * at befor. ****Parameters Used * none ****Parameters returned * - Variable to hold the no of Header recs counted * - Variable to hold the no of data recs counted *-- PROCEDURE COUNTREC PARAMETERS lcPathTo lnNoHeadRec lnNoDataRec llAllReady PRIVATE lcTemp l_string tllgo lcPathTo file_handle ifp_size ifp_top llAllReady = .F. IF FILE(lcPathTo) STORE FOPEN(lcPathTo) TO file_handle ELSE WAIT "Can not open file for copy chk "WINDOW ENDIF IF file_handle < 0 && Check for error opening file WAIT 'Cannot open or create output file' WINDOW NOWAIT ELSE STORE FSEEK(file_handle, 0, 2) TO ifp_size && Move pointer to EOF STORE FSEEK(file_handle, 0) TO ifp_top && Move pointer to BOF IF ifp_size <= 0 WAIT WINDOW 'This file is empty!' NOWAIT RETURN 0 ELSE && If not IF ifp_size > 500 ifp_size = 500 ENDIF tllGo = .T. lnNoHeadRec = 0 lnNoDataRec = 0 lcTemp = " " *do bugfind DO WHILE(tllGo) l_string = FGETS(file_handle, ifp_size) IF !EMPTY(l_string) lcTemp = SUBSTR(l_string,1,1) DO CASE CASE lcTemp = "H" lnNoHeadRec = lnNoHeadRec + 1 CASE lcTemp = "T" lnNoDataRec = lnNoDataRec + 1 CASE lcTemp = "U" llAllReady = .T. OTHERWISE WAIT "Not correct format for flat data file->" + ; lcPathTo WINDOW ENDCASE ELSE tllGo = .F. ENDIF ENDDO ENDIF = FCLOSE(file_handle) && Close the file ENDIF RETURN