How Do I Put An End Of Line Character In A TextBox

  • Thread starter Thread starter Christopher Lusardi
  • Start date Start date
C

Christopher Lusardi

How would I put an end of line character in the second line below?

Textbox1.Text = "Hello "
Textbox1.Text =
Textbox1.Text = "World"

Thanks,
Chris Lusardi
 
I didn't know vbcrlf existed. At the top of some of my programs I have
dim crlf as string = Chr(13) & Chr(10)
guess I don't need that but now I have to type vbcrlf instead of crlf.
 
cj said:
I didn't know vbcrlf existed. At the top of some of my programs I have
dim crlf as string = Chr(13) & Chr(10)
guess I don't need that but now I have to type vbcrlf instead of crlf.

No, you don't need it. Note that VB.NET has a 'ControlChars.NewLine'
constant too, and 'Environment.NewLine' will return the system's new line
character.
 
Herfried,

I once asked you to make a testset and you told than that you had not the
time to type that.

Why are you advicing that long code, while there is that simple vbcrlf.

In C# I find the 'ControlChars.NewLine' a very good alternative for the
literal. But VB has a better solution for that.

Cor
 
You saw it probably already, I forgot the :-)

Cor

Cor Ligthert said:
Herfried,

I once asked you to make a testset and you told than that you had not the
time to type that.

Why are you advicing that long code, while there is that simple vbcrlf.

In C# I find the 'ControlChars.NewLine' a very good alternative for the
literal. But VB has a better solution for that.

Cor
 
Is controlchars.newline available in both VB and C#? If so perhaps
Herfried is promoting using something that would be the same from
language to language. VB also has vbNewLine. Frankly everything is
getting long. I almost stuck with dimming my own, crlf, as it is 4
chars instead of vbCrLf's 6. And actually thought about using nl for
newline but it wasn't quite as obvious when reading the code. Anyway I
went with vbCrLf as it doesn't need a dim and I'll get used to it.

You saw it probably already, I forgot the :-)

Cor
 
cj said:
Is controlchars.newline available in both VB and C#?

No, 'ControlChars.NewLine' is part of "Microsoft.VisualBasic.dll".
language to language. VB also has vbNewLine. Frankly everything is
getting long. I almost stuck with dimming my own, crlf, as it is 4 chars
instead of vbCrLf's 6.

Well, you could import the 'ControlChars' type and then use 'NewLine' and
'CrLf' throughout your code, without any bad performance implications.
 
Cor Ligthert said:
I once asked you to make a testset and you told than that you had not the
time to type that.

Why are you advicing that long code, while there is that simple vbcrlf.

In C# I find the 'ControlChars.NewLine' a very good alternative for the
literal. But VB has a better solution for that.

Well, first, we have to distinguish between methods/properties to determine
the system's new line character and on getting a system-independent new line
character sequence. The first can be done using 'Environment.NewLine' in
both VB.NET and C#. For the latter there are different ways in VB.NET and
C#. In C# typically new line character sequences are embedded as escape
codes inside string literals:

\\\
string s = "Hello\r\nWorld"
///

The equivalent code in VB.NET would be

\\\
Dim s As String = "Hello" & ControlChars.CrLf & "World"
///

or alternatively

\\\
Dim s As String = "Hello" & vbCrLf & "World"
///

'vbNewLine' and 'ControlChars.NewLine' both are constants which have the
same value as 'vbCrLf'. IIRC 'vbNewLine' has been introduced in VBA once to
support /different/ newline character sequences in VBA on Windows and on the
Mac.

Personally I generally prefer 'ControlChars.NewLine' or 'vbNewLine' over
'ControlChars.CrLf' and 'vbCrLf' because its name is semantically more
meaningful and I do not care about the value of the constant too much.
However, if the exact character codes are important, then I prefer 'CrLf'
and 'vbCrLf'.
 
LOL

Herfried K. Wagner said:
Well, first, we have to distinguish between methods/properties to
determine the system's new line character and on getting a
system-independent new line character sequence. The first can be done
using 'Environment.NewLine' in both VB.NET and C#. For the latter there
are different ways in VB.NET and C#. In C# typically new line character
sequences are embedded as escape codes inside string literals:

\\\
string s = "Hello\r\nWorld"
///

The equivalent code in VB.NET would be

\\\
Dim s As String = "Hello" & ControlChars.CrLf & "World"
///

or alternatively

\\\
Dim s As String = "Hello" & vbCrLf & "World"
///

'vbNewLine' and 'ControlChars.NewLine' both are constants which have the
same value as 'vbCrLf'. IIRC 'vbNewLine' has been introduced in VBA once
to support /different/ newline character sequences in VBA on Windows and
on the Mac.

Personally I generally prefer 'ControlChars.NewLine' or 'vbNewLine' over
'ControlChars.CrLf' and 'vbCrLf' because its name is semantically more
meaningful and I do not care about the value of the constant too much.
However, if the exact character codes are important, then I prefer 'CrLf'
and 'vbCrLf'.
 
Back
Top