//----------------------------------------------- //Function to open a file and create an instream //Global variables declared // gFileStream InStream // gFile File //----------------------------------------------- OpenFile(pFilePath : Text[250]) Ok : Boolean Ok := TRUE; IF gFile.OPEN(pFilePath) THEN gFile.CREATEINSTREAM(gFileStream) ELSE Ok := FALSE; //--------------------------------------------------------------- // Function to read ; separated values from a file // Local Variables // lChar Text 1 // lArrayPosition Integer // // When you use this function you should declare an array like in the // parameter of the function. The valuse will be in that array. // As you can see the number of fields and length of the fields is limited to 250 // (which can be changed) //--------------------------------------------------------------- ReadLine(VAR pValues : ARRAY [250] OF Text[250]) Ok : Boolean lArrayPosition := 1; CLEAR(pValues); Ok := TRUE; WHILE NOT gFileStream.EOS DO BEGIN gFileStream.READTEXT(lChar,1); IF NOT (lChar = '') THEN BEGIN IF NOT (lChar = ';') THEN BEGIN pValues[lArrayPosition] := INSSTR(pValues[lArrayPosition],lChar,9999); END ELSE lArrayPosition += 1; END ELSE BEGIN EXIT; END; END; Ok := lArrayPosition > 1; //-------------------------------------------------------------------------------------------- //Function to read fixed width values from a file // Local variables // lArrayPosition Integer // lChar Text 1 // lPos Integer // // Before calling thsi function you should fill the array pFiledStart with the startpositions of the fields // and pFieldEnd with the endpositions of the fields. // -------------------------------------------------------------------------------------------------- ReadLineFields(VAR pValues : ARRAY [250] OF Text[250];pFieldStart : ARRAY [250] OF Integer;pFieldEnd : ARRAY [250] OF Integer) Ok : Boo lArrayPosition := 1; lPos := 1; CLEAR(pValues); Ok := TRUE; WHILE NOT gFileStream.EOS DO BEGIN gFileStream.READTEXT(lChar,1); IF NOT (lChar = '') THEN BEGIN IF(lPos >= pFieldStart[lArrayPosition]) THEN BEGIN IF lPos <= pFieldEnd[lArrayPosition] THEN BEGIN pValues[lArrayPosition] := INSSTR(pValues[lArrayPosition],lChar,9999) END ELSE BEGIN lArrayPosition += 1; pValues[lArrayPosition] := INSSTR(pValues[lArrayPosition],lChar,9999) END; END; lPos+= 1; END ELSE BEGIN EXIT; END; END; Ok := lArrayPosition > 1; //-------------------------------- //Function to close the file //-------------------------------- CloseFile() gFile.CLOSE();
Comments
Regards
http://www.AcumenConsulting.co.nz
Just a happy frood who knows where his towel is
Dataports do not work with at all with an Navision Application Server (NAS)
|To-Increase|