The problem is
Chr(13)
. This is one of the end-of-line separators. Please see:
http://en.wikipedia.org/wiki/Newline[
^].
None of end-of-line characters should appear in most controls and other UI elements, such as a menu item. Run your code under the debugger and make sure you never insert such thing. And even in other cases, when you really need to insert such thing, you should not use
Chr(13)
or anything else as an
immediate constant. As you can see from the article referenced above, it depends on OS, so you need to use the static property
System.Environment.NewLine
instead:
http://msdn.microsoft.com/en-us/library/system.environment.newline.aspx[
^].
One more, minor problem in your code: using string concatenation. Strings are
immutable, so using string concatenation repeatedly is bad (do I have to explain why). Instead, prefer using
string.Format
. If it is not suitable (for example, in loops), use the mutable class
System.Text.StringBuilder
:
http://msdn.microsoft.com/en-us/library/system.text.stringbuilder.aspx[
^].
—SA