If you read from a file with TEXMODE=TRUE, tabs will be converted to spaces with tab stops at position 9, 17, 25... Therefore, you will not find any tab characters anymore. Instead, use InStream.READTEXT and a field separator string according to Maximus's suggestion.
Furthermore, you should guard COPYSTR and DELSTR against the case where STRPOS did not find a field separator (i.e. PosCode=0).
At last, I believe FORMAT without additional parameters does not do anything useful in the construction FORMAT(COPYSTR(....
I created a text file with three "TAB" characters and tried to read it and it is able to recognise the TAB correctly. Pls try the below code.
//FileStream InStream
//FileTest File
//txt Text 250
//tabchar char
tabchar := 9;
FileTest.OPEN('C:\Users\MMV\Documents\MMV\Misc\tabdelimited.txt');
FileTest.CREATEINSTREAM(FileStream);
WHILE NOT (FileStream.EOS()) DO
BEGIN
FileStream.READTEXT(txt,1);
IF FORMAT(txt) = FORMAT(tabchar) THEN
MESSAGE('yes');
END;
FileTest.CLOSE();
See MMV's code for reading and looping, then use your code within the loop.
You can safely read a full line of text, as long as you can guarantee that each and every line fits into your text variable. Else you need to read the line in chunks, but this is not much different from reading from a file, only more flexible with streams.
I created a text file with three "TAB" characters and tried to read it and it is able to recognise the TAB correctly. Pls try the below code.
//FileStream InStream
//FileTest File
//txt Text 250
//tabchar char
tabchar := 9;
FileTest.OPEN('C:\Users\MMV\Documents\MMV\Misc\tabdelimited.txt');
FileTest.CREATEINSTREAM(FileStream);
WHILE NOT (FileStream.EOS()) DO
BEGIN
FileStream.READTEXT(txt,1);
IF FORMAT(txt) = FORMAT(tabchar) THEN
MESSAGE('yes');
END;
FileTest.CLOSE();
Best Regards,
MMV
Hi MMV,
i just curious how to make this happen
Data :
so it will prompt message word by word
-->
first CUST001, and then ITEM001 and then 8.... and then CUST001.... and so on
how to get the word as TAB Delimited as a separator
FileTest.OPEN('C:\Users\MMV\Documents\MMV\Misc\tabdelimited2.txt');
FileTest.CREATEINSTREAM(FileStream);
WHILE NOT (FileStream.EOS()) DO
BEGIN
FileStream.READTEXT(txt,1);
FileTest.SEEK(nextPOS);
FileTest.READ(tempChar);
nextPOS += 1;
IF tempChar IN [tabchar,LineFeed,CarriageReturn] THEN BEGIN
MESSAGE('Whole Text %1',WholeText);
WholeText := '';
IF tempChar IN [LineFeed,CarriageReturn] THEN
nextPOS += 1;
END ELSE
WholeText += txt;
END;
FileTest.CLOSE();
Though the above code is a round about mechanism, it works well based on the data you have mentioned in the post (only TAB delimited).
Comments
have you tried the following?
Define a variable called TAB of Type Char
Assign a value with code like this: TAB := 9;
Then reuse your code like this:
SFile.READ(vString);
PosCode:=STRPOS(vString,FORMAT(TAB));
vStringTransaction := FORMAT(COPYSTR(vString,1,PosCode-1));
vString:=DELSTR(vString,1,STRLEN(vStringTransaction) + STRLEN(FORMAT(TAB)));
but maybe because the delchr --> posode-1
there is an error message like this
Furthermore, you should guard COPYSTR and DELSTR against the case where STRPOS did not find a field separator (i.e. PosCode=0).
At last, I believe FORMAT without additional parameters does not do anything useful in the construction FORMAT(COPYSTR(....
i tried but the poscode still 0
any clue?
I created a text file with three "TAB" characters and tried to read it and it is able to recognise the TAB correctly. Pls try the below code.
//FileStream InStream
//FileTest File
//txt Text 250
//tabchar char
tabchar := 9;
FileTest.OPEN('C:\Users\MMV\Documents\MMV\Misc\tabdelimited.txt');
FileTest.CREATEINSTREAM(FileStream);
WHILE NOT (FileStream.EOS()) DO
BEGIN
FileStream.READTEXT(txt,1);
IF FORMAT(txt) = FORMAT(tabchar) THEN
MESSAGE('yes');
END;
FileTest.CLOSE();
Best Regards,
MMV
See MMV's code for reading and looping, then use your code within the loop.
You can safely read a full line of text, as long as you can guarantee that each and every line fits into your text variable. Else you need to read the line in chunks, but this is not much different from reading from a file, only more flexible with streams.
Hi MMV,
i just curious how to make this happen
Data :
so it will prompt message word by word
-->
first CUST001, and then ITEM001 and then 8.... and then CUST001.... and so on
how to get the word as TAB Delimited as a separator
//FileTest File
//txt Text 250
//tabchar Char
//WholeText Text 1024
//nextPOS Integer
//tempChar Char
//LineFeed Char
//CarriageReturn Char
tabchar := 9;
nextPOS := 0;
LineFeed := 10;
CarriageReturn := 13;
FileTest.OPEN('C:\Users\MMV\Documents\MMV\Misc\tabdelimited2.txt');
FileTest.CREATEINSTREAM(FileStream);
WHILE NOT (FileStream.EOS()) DO
BEGIN
FileStream.READTEXT(txt,1);
FileTest.SEEK(nextPOS);
FileTest.READ(tempChar);
nextPOS += 1;
IF tempChar IN [tabchar,LineFeed,CarriageReturn] THEN BEGIN
MESSAGE('Whole Text %1',WholeText);
WholeText := '';
IF tempChar IN [LineFeed,CarriageReturn] THEN
nextPOS += 1;
END ELSE
WholeText += txt;
END;
FileTest.CLOSE();
Though the above code is a round about mechanism, it works well based on the data you have mentioned in the post (only TAB delimited).