# Problem reading a TXT file

**URL:** <https://www.dynamicsuser.net/t/problem-reading-a-txt-file/7879>\
**Category:** Developers Forum\
**Created:** [November 11, 2003, 8:20pm UTC](https://www.dynamicsuser.net/t/problem-reading-a-txt-file/7879 "2003-11-11T20:20:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![JSoage](https://avatars.discourse-cdn.com/v4/letter/j/67e7ee/32.png) [@JSoage](https://www.dynamicsuser.net/u/JSoage)\
**Post date:** [November 11, 2003, 8:20pm UTC](https://www.dynamicsuser.net/t/problem-reading-a-txt-file/7879/1 "2003-11-11T20:20:07Z")

</div>

Does anybody know why if I call the following function as f\_txtRead5Chars(‘C:\Test.txt’); I get the following error “The text ‘ABCDEF’ in READ parameter no. 1 is too long.” ? PROCEDURE f\_txtRead5Chars@21(p\_txtFileName@1000000001 : Text[100]) r\_txtRead5Chars : Text[5]; VAR l\_fileCAB@1000000000 : File; BEGIN l\_fileCAB.TEXTMODE(FALSE); l\_fileCAB.OPEN(p\_txtFileName); l\_fileCAB.READ(r\_txtRead5Chars); l\_fileCAB.CLOSE; END; **FILE C:\Test.txt** ABCDEFGHIJKLMNOPQRSTUVWXYZ It is supposed that when TEXTMODE = FALSE, READ will determines the number of bytes to read based on the size of the variable (5) but the error message shows 6 chars. Thanks in advance, Jesús Soage

---

<div class="post-metadata">

**Author:** ![David](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@David](https://www.dynamicsuser.net/u/David)\
**Post date:** [November 11, 2003, 8:40pm UTC](https://www.dynamicsuser.net/t/problem-reading-a-txt-file/7879/2 "2003-11-11T20:40:58Z")

</div>

> quote:
> 
> * * *
> 
> _Originally posted by JSoage_  
> It is supposed that when TEXTMODE = FALSE, READ will determines the number of bytes to read based on the size of the variable (5) but the error message shows 6 chars.
> 
> * * *

Hi Jesus, When you set the TEXTMODE to false, it means that you want to work with a binary file. In binary mode, the READ function will read the number of bytes or your variable (ex: 4 for an integer, 1 for a char, etc.), but it will not work if you use Complex variables like the type ‘Text’, because this type does not have a fixed length (i.e. fixed number of bytes). So, you have two options: #1 TEXTMODE = TRUE and READ to a tmpString variable (max 1024 char) With TEXTMODE = TRUE, READ reads the entire line of a text file. You will then have to extract the data from this variable #2 TEXTMODE = FALSE and READ your file char by char See the example below: `myFile.TEXTMODE(FALSE); myFile.OPEN('C:\temp\patate.txt'); FOR i := 1 TO 5 DO BEGIN myFile.READ(mychar); myString5chars[i] := mychar; //myString5chars := myString5chars + FORMAT(mychar); END; MESSAGE(myString5chars); myFile.CLOSE;`
