How to read a .txt file, if it's even possible, character by character ?
Or if its not possible then by separated characters with 1 space.
Open it in BN and READ mode and read a Byte at a time FileReadInteger() and that will give you ASCII value of a character, more or less . . .
Thanks but for some reason i always get error 4099.Its frustrating...
Am i doing something wrong?
Outside function declaration
int CHARVEKTOR[]; int CHARACTER=0;
Init() function
int FILE=FileOpen("CHARACTER.txt", FILE_READ|FILE_BIN) ; int k=0; if(FILE>0) { while(!FileIsEnding(FILE)) { CHARVEKTOR[k]=FileReadInteger(FILE,1) ; k++; } FileClose(FILE); }
The file CHARACTER.txt is located in MetaTrader\experts\files and also made a copy of it into MetaTrader\tester\files just in case it doesnt regocnize it at the other location.
Thanks but for some reason i always get error 4099.Its frustrating...
Am i doing something wrong?
Outside function declaration
Init() function
The file CHARACTER.txt is located in MetaTrader\experts\files and also made a copy of it into MetaTrader\tester\files just in case it doesnt regocnize it at the other location.
Your array has zero elements . . .
int CHARVEKTOR[];
. . . unless you are resizing it somewhere ?
Your array has zero elements . . .
. . . unless you are resizing it somewhere ?
Yes you are right, i just fixed it
if(FILE>0) { while(!FileIsEnding(FILE)) { ArrayResize(CHARVEKTOR,k+1); CHARVEKTOR[k]= StrToInteger(FileReadString( FILE, 1)) ; k++; } FileClose(FILE); }
I also replaced the read integer with read string because if i read integer values it sometimes gave silly values, non corresponding to what was in the text file, so readstring is better for me.
Yes you are right, i just fixed it
I also replaced the read integer with read string because if i read integer values it sometimes gave silly values, non corresponding to what was in the text file, so readstring is better for me.
It is perhaps not a good idea, there are some characters not defined in Windows, and they would be either shifted or missed. Better to stick with the FileReadInteger.
It is perhaps not a good idea, there are some characters not defined in Windows, and they would be either shifted or missed. Better to stick with the FileReadInteger.
I'm not even sure it will work, read a string from a CSV file using FILE_CSV Mode OK, but using FILE_BIN will not give a string, will it ?
It is perhaps not a good idea, there are some characters not defined in Windows, and they would be either shifted or missed. Better to stick with the FileReadInteger.
No guys it works as it is like a wonder.Since the .txt file only has numbers in it.It's purpose was only to randomize the magic number :)
If i'd use the FileReadInteger.,then it will read very weird data when it reads a space, so the
FileReadString
is better in my case.
No guys it works as it is like a wonder.Since the .txt file only has numbers in it.It's purpose was only to randomize the magic number :)
Why would you ever want a random MN ?
Set a base MN for your EA then add in an additional 2 digits for the timeframe and make sure you check the Symbol() . . . doesn't this make things unique ?
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
How to read a .txt file, if it's even possible, character by character ?
Or if its not possible then by separated characters with 1 space.