limit f.READ to 250 characters...

Hi all, I have got an ascii text file with different line lenghts which I partly want to import into Navision and feed several tables with this data. I already wrote a codeunit to import this file… which works fine, until I noticed that a couple of these lines have more than 250 characters… In the end, I only need the first 200 characters of these strings, so I wonder if there is a way of limiting the f.READ to 250 characters without the need to redesign my whole codeunit. A possible solution would be to define a character variable, Txt, and read the text file character by character (f.READ(Txt)) but what about the performance? Any hints available?? Nils

Hi Nils. I’ve used the method of reading data in character by character and performance isn’t that bad. /Michael

…just for those interested - I can confirm that performance is fine, almost as fast as reading in the file line by line… Here a code example of how to extract the first 250 characters from each line: Global vars Txt Text 250 Chars Integer Local vars _Txt Text 250 _i Integer _z Integer _chr Char _chrOK Integer


ReadLine() NumChar : Integer

_Txt := ''; _i := 0;

REPEAT
  _i += 1;
  _chrOK := f.READ(_chr);
  _z := _chr;
  IF (_i < 250) AND (_z <> 10) AND (_z <> 13) THEN
    _Txt += FORMAT(_chr);
UNTIL (_z = 10) OR (_chrOK = 0);

Txt := _Txt;
NumChar := STRLEN(_Txt);

and you simply call to read a line:


Chars := ReadLine;

Saludos Nils

Hi, Use COPYSTR and STRLEN function after reading the line. First check the length of line characters with STRLEN function. If this is more than 250 characters, copy first 250 characters in new string variable by using COPYSTR function and store it in and rest character…

Hi Rajesh, the problem is the step before: to read the line you need to use the statement Intvar := f.READ(Textvar) which will give you the length of the line in Intvar and store the line in Textvar… but of course Textvar is limited to 250 characters… It is not possible to use neither STRLEN nor COPYSTR because you cannot analyze something that has not been read yet. … please correct me, if I understood you wrong. Saludos Nils

quote:


Originally posted by nilsm
Hi Rajesh, the problem is the step before: to read the line you need to use the statement Intvar := f.READ(Textvar) which will give you the length of the line in Intvar and store the line in Textvar… but of course Textvar is limited to 250 characters… It is not possible to use neither STRLEN nor COPYSTR because you cannot analyze something that has not been read yet. … please correct me, if I understood you wrong. Saludos Nils


I think you’re right. Rudidlo.

I believe what Rajesh was getting at was to import the data into a Text variable with a longer length (like 1000 perhaps), then do the manipulations to that string before putting it into the table. That’s what I would do, at least.

Hi everybody, The problem is you cannot have a text variable larger than 250. The way to do it is by setting the type or file read to binary: F.textmode(false). Then you make a variable 250 or even 1 character long (does not matter). And then you start reading. When calling f.read in binary mode the system will only read up to the length of the variable (so if the variable is 100 chars long the system will read 100 bytes / chars or less if you are at the end). The tough part will be processing the data. Nils should know where the usefull data ends and after you have to check for end of line (I believe is character 13) so you know you started a new line. Hope that helps. [;)] Cristi Nicola