Expected Result: MessageBox() reads the new line character and applies it properly Testing Line One
Testing Line Two | Which is exactly what you get void OnStart() { MessageBox("Error: could not open file." "\n\nMake sure the my_messages.txt file is located in the MQL4\\Files folder and press 'Ok' to continue" "\n\nPress 'Cancel' to disable My Messages", "File Not Found", MB_OKCANCEL); } Drop the "\r" unnecessary. I dropped the "+" It auto-combines adjacent literal strings. |
Expected Result: MessageBox() reads the new line character and applies it properly | Which is exactly what you get Drop the "\r" unnecessary. I dropped the "+" It auto-combines adjacent literal strings. |
I don't think you understand.
The part you quoted, I'm just displaying the code I used for reading the data from the text file.
The focus is on the displayMessage function, where a random element from the string array created from openFile() is outputted into the MessageBox() function.
I definitely don't. Why are you talking about MessageBox when you have a problem reading a text file.
There is nothing wrong with your displayMessage function as is. You have lines of text in the array, you message box one of them.
What you want, If I understand you, you want to read text from the file that is multiline. Why didn't you say that? You totally confused everything with the rest.
You can't read newlines from a text file. They terminate the line.
If you want multi-lines read, your file must contain a marker character(s) (not used in regular text e.g. "¶") and then substitute them (StringReplace) with \n in the MessageBox call.
I definitely don't. Why are you talking about MessageBox when you have a problem reading a text file.
You can't read newlines from a text file. They terminate the line.
If you want multi-lines read, your file must contain a marker character(s) (not used in regular text e.g. "@ ` ¦ © ¶") and then substitute them (StringReplace) with \n in the MessageBox call.
1. Read from file
2. Data from file to string array
3. Data from string array to MessageBox()
If I create a separate string array, such as,
sArray[] = { "Testing Line One\nTesting Line Two" };
and then
MessageBox(sArray[0],"My Messages");
I get the expected result.
But if I read the same string from a text file, put that string into a string array, and then read from that element in the string array into a MessageBox(), the \n special character is read explicitly rather than parsed as a new line.
xcuco3x:But if I read the same string from a text file, | What part of You can't read newlines from a text file. They terminate the line. was unclear? You can't read the new lines. |
| What part ofwas unclear? You can't read the new lines. |
I'm a little unclear too.
Contents of Messages.txt:
This is line 1\nThis is line 2
This script:
int handle = FileOpen("Messages.txt",FILE_READ|FILE_TXT); if(handle==INVALID_HANDLE) return; while(!FileIsEnding(handle)) Print(FileReadString(handle)); FileClose(handle);
Returns this:
2017.04.06 16:24:04.399 Test AUDCHF,M1: This is line 1\nThis is line 2
However, if you change Messages.txt to this:
This is line 1 This is line 2
The result is:
2017.04.06 16:24:55.826 Test AUDCHF,M1: This is line 2 2017.04.06 16:24:55.826 Test AUDCHF,M1: This is line 1
If I understand correctly, you'd like to know why this isn't being recognised?
This is line 1\nThis is line 2
If I create a separate string array, such as,
sArray[] = { "Testing Line One\nTesting Line Two" };
and then
MessageBox(sArray[0],"My Messages");
I get the expected result.
But if I read the same string from a text file, put that string into a string array,
You can not read that string from a text file. You can not create a text file with an embedded new line.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I'm reading from a text file, inputting the data into a string array, and outputting one of the lines from the string array into a message box.
I believe it's not due to using a string array because I created one separately, tried it out, and the new line character was read perfectly. Therefore, I believe it is due to how the text is read from the text file using FileReadString().
Expected Result: MessageBox() reads the new line character and applies it properly
Testing Line One
Testing Line Two
Actual Result: MessageBox() ignores the new line character and outputs it directly
Testing Line One\nTesting Line Two