mutil line txt box

J

Jason

Hello

For a VB novice can anyone help me with the following simple idea.

All I've got on my form is a Textbox, (mulitline = true) and a button.

When I click the button I will have some simple lines of text to be
displayed. How do I have...

Dim addLine As String = "Next Line"
Dim addLine As String = "Another Line"


TextBox1.Text = "Line one"
then the next line display Next Line
and the next display Another Line

What is the newline char? \n
 
J

Jason

If I write this..

TextBox1.Text = "Line one"vbCrLf
TextBox1.text "more Text"

It just overwrites the top line, with the next line, then the next.

I'm tring to display them on seperate line
1) Line one
2) more Text
3) something else

Or am i doing this wrong?
 
J

jvb

Try this...

Me.TextBox1.Text += "Line One" & vbCrLf
Me.TextBox1.Text += "Line Two" & vbCrLf

That will give you

Line One
Line Two
 
H

Herfried K. Wagner [MVP]

Jason said:
All I've got on my form is a Textbox, (mulitline = true) and a button.

When I click the button I will have some simple lines of text to be
displayed. How do I have...

Dim addLine As String = "Next Line"
Dim addLine As String = "Another Line"


TextBox1.Text = "Line one"
then the next line display Next Line
and the next display Another Line


\\\
Me.TextBox1.Text = _
"Line 1" & ControlChars.NewLine & _
"Line 2" & ControlChars.NewLine & _
"Line 3"
///
 
H

Herfried K. Wagner [MVP]

jvb said:
Me.TextBox1.Text += "Line One" & vbCrLf
Me.TextBox1.Text += "Line Two" & vbCrLf

Mhm... I suggest to use '&=' instead of '+=' to concatenate strings.
 
J

Jason

One more quick and easy question.
Me.TextBox1.Text += "Line Two" & vbCrLf

How can I make that line BOLD?

Thanks again
 
J

jvb

Is there any reason that &= is better than +=? I have always used the
+. Am I going against convention?
 
T

The Grim Reaper

You can't in a standard text box.
You'll need to use the rich text box ... different game altogether!
_______________________________
The Grim Reaper
 
J

Jason

Anyone...

when I run this
Me.TextBox1.Text += "Line One" & vbCrLf
Me.TextBox1.Text += "Line Two" & vbCrLf

I get...

Line One
Line Two

But both lines are selected, is that supposed to be that way? How can I get
rid of the highlighting?
 
T

The Grim Reaper

I was going to say "you're going against convention!".... but then I checked
my local MSDN and found;

&=
Concatenates a String expression to a String variable or property and
assigns the result to the variable or property.

+=
Adds the value of a numeric expression to the value of a numeric variable or
property and assigns the result to the variable or property. Can also be
used to concatenate a String expression to a String variable or property and
assign the result to the variable or property.

So there you go!
____________________________________
The Grim Reaper
 
H

Herfried K. Wagner [MVP]

The Grim Reaper said:
I was going to say "you're going against convention!".... but then I
checked my local MSDN and found;

&=
Concatenates a String expression to a String variable or property and
assigns the result to the variable or property.

+=
Adds the value of a numeric expression to the value of a numeric variable
or property and assigns the result to the variable or property. Can also
be used to concatenate a String expression to a String variable or
property and assign the result to the variable or property.

Mhm... But I remember the documentation for '&' recommends to use '&' for
string concatenation instead of '+'.
 
T

The Grim Reaper

Me.TextBox1.SelectionStart = 0
Me.TextBox1.SelectionLength = 0

(I haven't had cause to use them much before, so experiment with what you
want to achieve)
___________________________________
The Grim Reaper
 
C

Cor Ligthert [MVP]

Hi,

Try this one with option strict off and be happy

dim a as string = "1"
a += 1

Cor
 
J

Jason

Thanks

Shouldn't that be in the properties of the Text Box?

Also how do you make a one line of text bold?


Me.TextBox1.Text += "Line One" & vbCrLf
Me.TextBox1.Text += "Line Two" & vbCrLf
 
J

jvb

To have only one line bold, you have to use a RichTextBox. Select the
text you want and execute this line:

rtb.SelectionFont = New Font(rtb.Font, FontStyle.Bold)

where rtb is the RichTextBox.
 
J

Jason

If I've got this

Me.RichTextBox1.Text = "In Rich Text Box"
Me.RichTextBox1.Text &= "Line two" & vbCrLf
How do I make the second line BOLD?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top