|
-
Feb 16th, 2003, 03:51 PM
#1
Thread Starter
Fanatic Member
CString and Escape Sequence Inconsistency ...
Hi Everyone,
I've encountered a problem that I can't solve .... and it seems that it shouldn't be a problem at all! I'm trying to populate a (CString) multiline edit box with a CString value that contains "\r\n". If I populate the edit box as follows, everything works fine with the Lines being on different rows:
VB Code:
m_edtMessage = "Line1\r\nLine2\r\nLine3\r\nLine4";
UpdateData(FALSE);
But if I use a variable instead, such as:
VB Code:
m_edtMessage = g_miParameterInfo[sArrayCtr].sz_Parameter;
UpdateData(FALSE);
, everything just appears on the first line, including "\r\n".
Can anyone help me out? This seems straightforward but I don't see why the variable method is not working.
Thanks in advance.
OneSource
-
Feb 16th, 2003, 04:00 PM
#2
What is the content of the variable? A command line parameter?
Escape sequences have their name for a reason.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Feb 16th, 2003, 07:46 PM
#3
Thread Starter
Fanatic Member
Corned Bee ...
Thanks for your reply. I apologize for the confusion.
I'm relatively new to Visual C++, so I'm not sure what a "command line paramenter" is. But the content of the variable is exactly the same as the string in my first post, namely "Line1\r\nLine2\r\nLine3\r\nLine4". I tried populating the edit box with the string and it worked just fine (the edit box contained 4 lines of text). But if I assign the string to the variable and use the variable to populate the edit box, there are no hard returns ... everything appears on the first line. Corned Bee, any help you or anyone else could provide would be greatly appreciated.
Thanks,
One Source
-
Feb 17th, 2003, 05:01 AM
#4
How do you assign the string to the variable?
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Feb 17th, 2003, 09:38 AM
#5
Thread Starter
Fanatic Member
Corned Bee ...
like this:
VB Code:
g_miParameterInfo[sArrayCtr].sz_Parameter = "Line1\r\nLine2\r\nLine3\r\nLine4";
-
Feb 17th, 2003, 12:58 PM
#6
This is indeed strange...
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Feb 17th, 2003, 12:59 PM
#7
Could you upload your entire code or is it copyrighted or closed?
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Feb 17th, 2003, 02:37 PM
#8
Thread Starter
Fanatic Member
Corned Bee ...
My project is rather big and also has a database component; therefore, it wouldn't be a good idea to upload it.
I created a little test app and the multiline edit box did display correctly even when I used a variable to populate it. So, I guess the problem is that the CString variable in my problem app is being populated with info. from an Access database. After that, I am putting the variable info. into the edit box. I don't know why this would be a problem because I'm using CStrings for all of the data transfers. The string in the database is, for example, "Line1\r\nLine2\r\nLine3\r\nLine4", but the "\r\n" 's are not being interpreted as such by VC++. Any ideas? 
Thanks ...
-
Feb 17th, 2003, 03:23 PM
#9
Monday Morning Lunatic
Ahhhh. The \r and \n are interpreted by the *compiler*, not the runtime. You'd need to actually have the characters 10 and 13 in there for it to notice.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Feb 17th, 2003, 03:30 PM
#10
Thread Starter
Fanatic Member
Parksie ...
It definitely sounds like the solution is near!
You'd need to actually have the characters 10 and 13 in there for it to notice.
Will you please show me how these characters should be stored in the database in order for the runtime to notice them?
Thanks.
-
Feb 17th, 2003, 03:35 PM
#11
Monday Morning Lunatic
Um. You just need to somehow force it in there. How are you storing the data? In your interface, if you're entering the values, have that check for \n or \r and automatically replace it.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Feb 17th, 2003, 03:39 PM
#12
Thread Starter
Fanatic Member
Parksie ...
Automatically replacing the data isn't a problem. But I was asking what format the "10 and 13" needed to be in in order for the VC++ runtime to recognize them. For example, would this register as a hard return: "\10\13"?
-
Feb 17th, 2003, 03:45 PM
#13
Monday Morning Lunatic
No, look up how to embed octal escape codes. But that will still only be at the *compiler*. You need to tell it to put characters '\n' and '\r' in, to replace the strings "\n" and "\r".
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Feb 18th, 2003, 10:37 AM
#14
Thread Starter
Fanatic Member
As good as it gets?
Parksie,
With a little work, I was able to populate the multiline edit box using the information from your post. I couldn't simply store '\r' and '\n' in the database field because it would just be viewed as part of the field itself just like "\r\n" is. I guess that this is "as good as it gets" as far as trying to achieve my desired end result. But things would be much simpler if the VC++ runtime interpreted "\r\n" like the compiler does. There's no way to make it do this?
By the way, thanks for your help Parksie. You too, Corned Bee. You probably would have been able to figure out the problem if I had mentioned in the beginning that the info. populating the string variable was coming from a database field. 
Thanks again,
OneSource
-
Feb 18th, 2003, 10:44 AM
#15
Monday Morning Lunatic
No, you need to convert the \r and \n to their respective numbers *yourself*. The escape codes are a feature of the compiler. It's simple enough to do.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Feb 18th, 2003, 03:10 PM
#16
That's what I was thinking.
Anyway, it wouldn't be good if the runtime interpreted escape sequences. You might overlook a single place where it happens and you already had a bug.
It's easy enough to write such a function yourself.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|