Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String concatenation & control codes

Status
Not open for further replies.

kaiyote

Programmer
Jun 18, 2004
3
US
New to fortran, I am running into some issues when attempting to combine string concatenation with the "//" operator and control codes (such as the new line "\n") with the QuickWin function messageBoxQQ.

The following code properly displays the message box with its output:

sMsg = 'First and\nSecond lines'C
iRet = messageBoxQQ(sMsg,'Title'//' bar'C, MB$OK)

Title Bar
---------
First and
Second lines

When I try to concatenate, the output fails:

sMsg = 'First and\nSecond'
sMsg2 = TRIM(sMsg)//' lines'C
iRet = messageBoxQQ(sMsg2,'Title'//' bar'C, MB$OK)

Title Bar
---------
First and\nSecond lines


sMsg = 'First and\nSecond'C
sMsg2 = TRIM(sMsg)//' lines'C
iRet = messageBoxQQ(sMsg2,'Title'//' bar'C, MB$OK)

Title Bar
---------
First and
Second

One of the key applications, is to be able to display an error message of

'File filename not found.'

by concatenating the filename variable with the remainder of the string.

Apparantly, I have a misconception regarding the use of either control codes and null-terminated strings in Fortran, the concatenation operators, or the TRIM function. (or perhaps all three!) I do understand the results of the last example, as the EOL character apparantly was concatenated within the string, causing early termination. The other is beyond me.

I would greatly appreciate any insights anyone may share to help me produce the desired results.
 
I don't have a Fortran system to try things out at the moment but try one of the following

CHAR(13)
CHR(13)
CHAR(10)
CHR(10)

instead of '\n'. You may need both 10 and 13 (LF and CR).
 
xwb,

Thank you for the attempt, though it was to no avail. I have already tried the combined LF & CR control codes. Additionally, note that in the null-terminated constant string, the \n control code executes correctly.

As a side note, I neglected to mention this earlier :

Windows XP Pro, Compaq VF Studio 6.6.0

kaiyote
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top