TextBox or RichTextBox

gnappi

Newcomer
Joined
Mar 7, 2006
Messages
13
I'm trying to make a multiline scrolling textbox but with TextBox (Multiline=True)
or RichTextBox (Multiline=True) the last string overwrites the text. What am I missing?


Thanks,

Gary
 
Cags said:
What do you mean the last string overwrites the text. You will have to provide some code, as I'm not sure what your problem is.

Print one line CR/LF
Print one line CR/LF

Something like:

RichTextBox1.Text = "test:"
RichTextBox1.Text = "test2"
or
TextBox2.Text = "Test1 " & vbCrLf & vbCrLf
TextBox2.Text = "test2"

Right now EVERYTHING prints on one line, meaning that the test2 message overwrites test1.

Regards,

Gary
 
HI,

try using the += operator to append text, for example:
RichTextBox1.Text = "This is "
RichTextBox1.Text += "some text."
The RTB should now contain "This is some text.", rather than "some text." which you would have got if you hadn't used +=.

Hope that helps, sorry if I misunderstand the question :)
 
Of course it does, I thought that might be what your doing. First you are assigning Test1 and a couple of char return line feeds to the Text property. Then you assign the Text property as equal to test2. Using the uquals operator in this manner will assign the object on the left equal to the object on the right, not add it.

If you wish to append more text you should use one of these methods.
Visual Basic:
RichTextBox1.Text += "test2"
' or alternatively
RichTextBox1.Text = RichTextBox1.Text & "test2"
[edit]Beaten to the punch....[/edit]
 
Cags said:
Of course it does, I thought that might be what your doing. First you are assigning Test1 and a couple of char return line feeds to the Text property. Then you assign the Text property as equal to test2. Using the uquals operator in this manner will assign the object on the left equal to the object on the right, not add it.

If you wish to append more text you should use one of these methods.
Visual Basic:
RichTextBox1.Text += "test2"
' or alternatively
RichTextBox1.Text = RichTextBox1.Text & "test2"
[edit]Beaten to the punch....[/edit]

Thanks for the replies, but I finally came up with a solution using the following syntax.

TextBox2.AppendText(vbCrLf + ("linetest1 "))
TextBox2.AppendText(vbCrLf + ("linetest2 ") + (speaker_status))
 
Just so you know, you really don't need all those parentheses.
Visual Basic:
TextBox2.AppendText(vbCrLf + "linetest1 ")
TextBox2.AppendText(vbCrLf + "linetest2 " + speaker_status)
Would be exactly the same as:
Visual Basic:
TextBox2.AppendText(vbCrLf + ("linetest1 "))
TextBox2.AppendText(vbCrLf + ("linetest2 ") + (speaker_status))
You might want to consider using the & and &= operators for joining strings because it makes it clear that you want to concatenate, not add.
Visual Basic:
Dim Result As Object
Dim Value1 As Integer = 10
Dim Value2 As Integer = "11"
 
Result = Value1 + Value2 ' 10 + "11" = 21? Or "1011"?
Result = Value1 & Value2 ' 10 & "11" = "1011" because & can't add.
 
Back
Top