Tab Delimitted File

hi

does anyone know how to extract values from a tab delimitted string ?

(not via dataport, since i need some manipulations on the text before inserting into the table) ?

thanks, amir

I am not sure that I understand you correctly. But you can open a file with tab delimited values in Excel or in Access. If you want to manipulate the data within, it is easier to manipulate it in Excel. After that you can save it in a tab delimited format.

probably you misunderstood me

the code problem for me to handle is loading a tab delimitted file (which is very simple thing to do with dataports, but its not what i asked for)

manipuliate the data and then insert it to the database via insert.

the difficulty that i’m havin is seperating the data on the instream value .

amir.

Oops, that is programming. I can’t help you with this.[:S]

You can all do that in dataport too. Manipulate the data as you like and insert into table using Insert or Modify, its better you use dataport.

yes,

maybe so

but dataport works as a transaction block

if some of the data is wrong, all transaction is rolled back

that is not what i am looking for.

amir.

If you use COMMIT after INSERT or MODIFY, it wouldn’t rollback all transactions.

If you use COMMIT after INSERT or MODIFY it wouldn’t rollback all transactions.

it is right (in case of codeunit, maybe i don’t know how to do the commit in dataports)

but still, i don’t know how to extract values from tab delimitted string values.

maybe you can help me if you did something like that.

Amir i guess you have to read documentation on dataports and see what they can do.

Have you looked at the use of regular expressions? This way you can look for specific data within a string and then use that, rather than relying on data location.

Andrew

Why don’t you want to use a dataport? The only reason not to use a dataport that I know is performance. How many records are you importing?

In dataport’s properties set FileFormat=Variable and “FieldSeparator” = (including then less-/greater-than-signs).

Hi Amir :-),

as the others did, I recommend to you the use of a Dataport, but as I can see nobody is telling you how to extract values from a tab delimitted string in Navision, so here you are.

After this, you decide how to do it, or what method fits better to fix your problem.

You need to have into account several things:

  1. In NAV, if you use TEXTMODE(TRUE), TABS are converted from ASCII 9 to ASCII 32 (space). If you find for spaces in your string, this can be not successful as you probably have normal spaces in a Description for example, so this wont be valid.

  2. You can then use TEXTMODE(FALSE), then it will open in BINARY mode, and the chars won’t be converted. Then you can compare or find for a TAB in your string.

EXAMPLE:

VARs: Yourfile FILE, Char9 - Char; FileName - Text 250, YourStringWithTABS - Text 300, Position Integer

CODE:

Char9 := 9;

Yourfile.TEXTMODE(FALSE);

Yourfile.OPEN(FileName);

REPEAT

Yourfile.READ(YourStringWithTABS);

Position := STRPOS(YourStringWithTABS, FORMAT(Char9));

Field1InNAV := COPYSTR(YourStringWithTABS,1,Position);

UNTIL file.POS = file.LEN;

I hope this is what you wanted to hear from the beggining :-).

Have a nice day!;

Vane

i saw your response just now as i tried to post my solution to this

so here it is :

sChar := 9;
oFile.OPEN(sFileName);
oFile.CREATEINSTREAM(oInStream);
MyTestTable.INIT();
WHILE NOT (oInStream.EOS) DO BEGIN
Int :=oInStream.READTEXT(Txt,200);
NewString := CONVERTSTR(Txt, FORMAT(sChar), ‘,’);
Txt2Array(NewString);
MyTestTable.CustomerCode := TxtArray[1];
MyTestTable.AccountCode := TxtArray[2];
MyTestTable.InvoiceNumber := TxtArray[3];
bOK := EVALUATE(xDate,TxtArray[4]);
MyTestTable.Date := xDate;
bOK := EVALUATE(xDecimal,TxtArray[5]);
MyTestTable.InvoiceAmount := xDecimal;
bOK := EVALUATE(xDecimal,TxtArray[6]);
MyTestTable.VATAmount := xDecimal;
MyTestTable.Currency := TxtArray[7];
MyTestTable.CustomerDesc := TxtArray[8];
MyTestTable.INSERT;
END;
oFile.CLOSE();
MESSAGE(‘Finished Loading !!!’);

Txt2Array(sTxtString : Text[200])
NewString := sTxtString;
FOR iCount := 1 TO 8
DO BEGIN
iPosition := STRPOS(NewString, ‘,’);
IF iPosition > 0 THEN BEGIN
TempString := DELSTR(NewString, iPosition);
NewString := DELSTR(NewString, 1, iPosition);
TxtArray[iCount] := TempString;
END
ELSE BEGIN
TxtArray[iCount] := NewString;
END;
END;

very good as a 1 week experience, ha ?

LOL

as a final question, the text file that i’m having contains words in hebrew, and after inserting it to the database, it become jibrish

for example : Ì.ü.Ì.ÞÌÍÔØ 2009 ÍÜ"Ù

do you know a way to convert code page as i do in .net languages ?

thanks in advance.

amir.