//------------------------------------------------------------> // CalcFlatFileSize.pkg // // Running a progress bar when importing a file of unknown // size is sort of sketchy, so the following function was // created to estimate the number of lines in the file. The // idea is to average the length of the first 100 lines and // divide it into the file size to obtain a number of lines // that might be close. Of course if the line lengths vary // a great deal, the average could be off by as much as 20%, // but this is a "guesstament" anyway. //------------------------------------------------------------> Use vWin32fh.pkg Use WinFileSize.pkg Function Calc_Flat_File_Lines String sFileName Integer iTestNumLines Integer iChNum Returns Integer string sInputLine Integer iFileSize Integer iLine Integer iLineSize Integer iNumLines Get vWin32_APIFileSize sFileName to iFileSize Direct_Input Channel iChNum sFileName If not (SEQEOF) Begin // Check length of first 20 lines For iLine From 1 to iTestNumLines Readln Channel iChNum sInputLine Add (length(trim(sInputLine))) to iLineSize Loop // Average line length Move (iLineSize/iTestNumLines) to iLineSize // Full file size Move (iFileSize/iLineSize) to iNumLines End Close_Input Channel iChNum Function_Return iNumLines End_Function