Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Messagebox newline

tropfen
New Contributor I
1,754 Views
Hello,

i am using a messagebox call (to be correct the xeffort wrapper xmessagebox). i would like to add a line break to start a text in a new line.

From VBA i remember the syntax \\n. I have tested it but it do not work.

A search on the forum has no results.

Thanks in advance
Frank
0 Kudos
15 Replies
netphilou31
New Contributor II
1,754 Views

Hi Franck,

I think that you need to add a newline character manually in your string to have the correct behavior.

Example : string = "First line" // char(#0A) // "Second line"C

Don't forget the final C to declare that it is an ansi string (i.e. terminated by a null character)

N.B: #0A is the ascii code for LineFeed character

Best regards,

0 Kudos
GVautier
New Contributor II
1,754 Views
Hello

I think that "c" strings are "interpreted" at compilation time.

So the string "first line\nsecond line"c will integrate a line feed.
0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,754 Views
Quoting netphilou31

Hi Franck,

I think that you need to add a newline character manually in your string to have the correct behavior.

Example : string = "First line" // char(#0A) // "Second line"C

Don't forget the final C to declare that it is an ansi string (i.e. terminated by a null character)

N.B: #0A is the ascii code for LineFeed character


Close, but I think that one actually needs CR+LF (char(13)//char(10)) to actually make a linebreak in a message or edit box.

0 Kudos
netphilou31
New Contributor II
1,754 Views
For what I know,the standard MessageBox function (i.e. from Windows API) works as I mention previously.

I think that the compiler interprets the final C character to transform the string into C string but I think that it does not interprets the characters inside the string.

To Jugoslav: You are problably right, I was not sure if the CR character was mandatory or nor. As far as I remember I get the function working correctly without the CR character but may be that was a side effect.

Best regards,
0 Kudos
tropfen
New Contributor I
1,754 Views
Hello Jugoslav,

could you please add this information in your help file of XEffort for the XMessageBox.

An other question about XEffort. Is there a time line for a IVF 12 Release?

Thanks in advance
Frank
0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,754 Views
Quoting tropfen
An other question about XEffort. Is there a time line for a IVF 12 Release?

Thanks in advance
Frank

There was, but it is broken. I'm helluva busy, and can't make any promises. :( Your question is duly noted though, and I'll try to find some spare time.

0 Kudos
anthonyrichards
New Contributor III
1,754 Views
Many times I have used CHAR(10)//CHAR(13) added to MessageBox strings to make them display over more than one line.

The point made about the compiler interpreting C-strings at compile time only applies if it can see ALL the characters in the string at compile time. It cannot and will not 'interpret' the character pair \r\n as an escape sequence unless it can 'see' it, for example in

string='This is a very, very, very long line that I want to\r\nsplit into two lines'c

The terminal C defines the preceding character string as a C-string. This will then be hard coded at compile time with the substitution of the required control characters in place of '\r' and '\n'.

This string can be built at execution time using

splitstring=char(10)//char(13)
string1='This is a very, very, very long line that I want to'
String2='split into two lines'
string3=string1//splitstring//string2//char(0)

with char(0) adding the null terminator required by C-strings for use in Windows API calls such as MessageBox or GetOpenFileName.

If you tried

string3=String1//'\r\n'//string2//char(0)

then the string '\r\n' will NOT be interpreted as an escape sequence, but as four characters, '\r\n'.
0 Kudos
tropfen
New Contributor I
1,754 Views
Hello,

to understand your reply correctly, i would like to create two examples.

Does it mean:
- when ever I use a fixed character string including \r\n or char(13)//char(10) end ending up with a final c it will work [e.g. 'Hello '//char(13)//char(10)//' world'//char(0)]

- when ever i use a composite character string like trim(string1)//char(13)//char(10) //trim(string2)//char(0) it will NOT work [i will have no new line but nice additional characters]

Thanks in advance
Frank
0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,754 Views
Quoting tropfen
Hello,

to understand your reply correctly, i would like to create two examples.

Does it mean:
- when ever I use a fixed character string including \r\n or char(13)//char(10) end ending up with a final c it will work [e.g. 'Hello '//char(13)//char(10)//' world'//char(0)]

- when ever i use a composite character string like trim(string1)//char(13)//char(10) //trim(string2)//char(0) it will NOT work [i will have no new line but nice additional characters]

No. Both of your examples will work. As long as the CR+LF characters are there, and the string is char(0)-terminated, you'll be fine.

Basically, one should pick one style and stick with it. Since the "C-style" notation (\r\n) is non-standard, and only slightly shorter, I prefer always using char() and concatenation operator //. Of course, you can define a character(2), parameter:: CRLF=char(13)//char(10) and use that.

0 Kudos
GVautier
New Contributor II
1,754 Views
Hello

The example shown on the Microsoft reference page to MessageBox function http://msdn.microsoft.com/en-us/library/ms645505%28v=vs.85%29.aspx only mentions a \n to insert a newline :

[bash]int msgboxID = MessageBox(
        NULL,
        (LPCWSTR)L"Resource not availablenDo you want to try again?",
        (LPCWSTR)L"Account Details",
        MB_ICONWARNING | MB_CANCELTRYCONTINUE | MB_DEFBUTTON2
    );
[/bash]


0 Kudos
Robert_van_Amerongen
New Contributor III
1,754 Views
In my MessageBox use I do only use ACHAR(13) to force a new line and that works fine. I do not seen any effect when I use ACHAR(10)//ACHAR(13)

Robert
0 Kudos
Steven_L_Intel1
Employee
1,754 Views
In my experience, \n is sufficient.
0 Kudos
Robert_van_Amerongen
New Contributor III
1,754 Views
Steve,

you are correct. But because I prefer to have my source as much as possible conforming the Fortran standard I use in this case

"First line"//ACHAR(13)//"Second Line"//ACHAR(0)

in stead of

"First line\nSecond Line"C

although this will work as well!

Best regards,
Robert
0 Kudos
Steven_L_Intel1
Employee
1,754 Views
You could use C_NEW_LINE and C_NULL from ISO_C_BINDING to be more portable. I was just pointing out that it is not necessary to also have the CR character in there.
0 Kudos
Robert_van_Amerongen
New Contributor III
1,754 Views
Steve,

Thanks for this idea!

Best regards,
Robert
0 Kudos
Reply