How to Add Carriage return line feed to string (globalization)
-
Here is todays little problem :-) Usually I would write soemthing like this : ErrorMessage = "First Line" & vbCrLf & "second Line" MSGbox(ErroMessage) - This will produce a two line message What I need to do is to write the code like this ErrorMessage = "First Line ??Linefeed?? second Line" - Notice This is just one continius string not an assembled string as in the original. MSGbox(ErroMessage) should then also display two lines How do I do this the most straigh forward way ? The reason I'm trying to do this is for globalization of our software This approach would make it easy to translate any error message into another language thanks Georg
-
Here is todays little problem :-) Usually I would write soemthing like this : ErrorMessage = "First Line" & vbCrLf & "second Line" MSGbox(ErroMessage) - This will produce a two line message What I need to do is to write the code like this ErrorMessage = "First Line ??Linefeed?? second Line" - Notice This is just one continius string not an assembled string as in the original. MSGbox(ErroMessage) should then also display two lines How do I do this the most straigh forward way ? The reason I'm trying to do this is for globalization of our software This approach would make it easy to translate any error message into another language thanks Georg
Georg Kohler wrote:
ErrorMessage = "First Line ??Linefeed?? second Line" - Notice This is just one continius string not an assembled string as in the original.
But you constuct it programmatically or is this string stored somewhere else? The problem is that I don't see the difference between those two variations is you still create the message text in the program.
The need to optimize rises from a bad design.My articles[^]
-
Here is todays little problem :-) Usually I would write soemthing like this : ErrorMessage = "First Line" & vbCrLf & "second Line" MSGbox(ErroMessage) - This will produce a two line message What I need to do is to write the code like this ErrorMessage = "First Line ??Linefeed?? second Line" - Notice This is just one continius string not an assembled string as in the original. MSGbox(ErroMessage) should then also display two lines How do I do this the most straigh forward way ? The reason I'm trying to do this is for globalization of our software This approach would make it easy to translate any error message into another language thanks Georg
Hi, if you want the multi-line string to be a single string in your database or your localized resource, how about this: - use a special substring to indicate NEWLINE (e.g. use \n like C/C++/Java/C# do) - then replace it by actual newline at run-time; in VB.NET that would be
myString=myString.Replace("\n", Environment.NewLine)
I don't know how it would look in ancient VB. - obviously reading the database/resource and replacing \n would fit nicely in a little method/function. :)Luc Pattyn [Forum Guidelines] [My Articles]
I use ListBoxes for line-oriented text output (not TextBoxes), and PictureBoxes for pictures (not drawings).
modified on Sunday, January 18, 2009 5:33 PM
-
Hi, if you want the multi-line string to be a single string in your database or your localized resource, how about this: - use a special substring to indicate NEWLINE (e.g. use \n like C/C++/Java/C# do) - then replace it by actual newline at run-time; in VB.NET that would be
myString=myString.Replace("\n", Environment.NewLine)
I don't know how it would look in ancient VB. - obviously reading the database/resource and replacing \n would fit nicely in a little method/function. :)Luc Pattyn [Forum Guidelines] [My Articles]
I use ListBoxes for line-oriented text output (not TextBoxes), and PictureBoxes for pictures (not drawings).
modified on Sunday, January 18, 2009 5:33 PM
Actually that's what I ended up doing last night .. I was just "fishing" to see if there is a different way to do this I ended up using @LF@ as the string to be replaced by the Environment.NewLine I have to look int using \n instead - stick to the standard if possible ... Anyway - thanks for taking the time to answer my question :-) As always "you guys" haven been great! Georg
-
Actually that's what I ended up doing last night .. I was just "fishing" to see if there is a different way to do this I ended up using @LF@ as the string to be replaced by the Environment.NewLine I have to look int using \n instead - stick to the standard if possible ... Anyway - thanks for taking the time to answer my question :-) As always "you guys" haven been great! Georg
You're welcome. :)
Luc Pattyn [Forum Guidelines] [My Articles]
I use ListBoxes for line-oriented text output (not TextBoxes), and PictureBoxes for pictures (not drawings).
-
Georg Kohler wrote:
ErrorMessage = "First Line ??Linefeed?? second Line" - Notice This is just one continius string not an assembled string as in the original.
But you constuct it programmatically or is this string stored somewhere else? The problem is that I don't see the difference between those two variations is you still create the message text in the program.
The need to optimize rises from a bad design.My articles[^]
Actually there is a difference - at least it seems to me :rolleyes:
ErrorMessage = "First Line" & vbCrLf & "second Line"
' This will produce a two line message
ErrorMessage = "First Line vbCrLf second Line"
' will not produce a two line message(maybe replacing VBCrlf with something else would also work - but here is my solution so far)
LogMessage = "First Line \n second Line"
LogMessage = LogMessage.Replace("\n", Environment.NewLine)
MSGbox(Logmessage) ' will again produce a two line message"First Line \n second Line" is what get's stored as a resource - as you can see it will be easy to change this into another language as you can add the line feeds wherever you need to. In my code I also add Variables to the message - again this will allow for easy translation into another language. A typical error message might look like this
" Error detected in line \VAR1 \n Dublicate \Var2 values detected!"
This might end up looking like this: ..... Error detected in line 12 Dublicate N values detected! ....
-
Actually there is a difference - at least it seems to me :rolleyes:
ErrorMessage = "First Line" & vbCrLf & "second Line"
' This will produce a two line message
ErrorMessage = "First Line vbCrLf second Line"
' will not produce a two line message(maybe replacing VBCrlf with something else would also work - but here is my solution so far)
LogMessage = "First Line \n second Line"
LogMessage = LogMessage.Replace("\n", Environment.NewLine)
MSGbox(Logmessage) ' will again produce a two line message"First Line \n second Line" is what get's stored as a resource - as you can see it will be easy to change this into another language as you can add the line feeds wherever you need to. In my code I also add Variables to the message - again this will allow for easy translation into another language. A typical error message might look like this
" Error detected in line \VAR1 \n Dublicate \Var2 values detected!"
This might end up looking like this: ..... Error detected in line 12 Dublicate N values detected! ....
I think that's a very good solution. I've used that system a lot. The only thing is that you may consider running the replace twice. First put the variables in place and then format the string with newlines. I sometimes have strings in variables that also contain \n. Doing this in two phases also replaces the newlines from variables correctly.
The need to optimize rises from a bad design.My articles[^]