שתף באמצעות


Adding additional lines to multi-line text box?

Question

Friday, April 6, 2012 3:23 PM

Hello all,

I know I'm close, but not close enough.  I have a line of data that represent a data import.  When the import is done, I would like to keep that exsisiting line, and add another line for the next import.  So I have a display of mulitiple lines, showing multiple Imports.

So this is one I have for the first section, it loops through the data so you see the rows incrementing

  TextBox1.Text = clsDatRow.iFirstVal.ToString + " ROWS:" + iCountRows.ToString + "  " + Date.Now.ToString
                        TextBox1.Refresh()

Now, I can I keep the line of data, and add a new line so for the next import, it does the same thing.  It ried vbnewline, but it just clears that line, it doesn't move down to a next line.

Thanks!

Rudy

All replies (6)

Saturday, April 7, 2012 5:16 AM ✅Answered

People here are on the right track but they haven't combined their posts to provide you with exactly what you want, you want to keep the existing value as well as input data on a new line. You can either use &= as jwavila had suggested or you can use the AppendText method for the Textbox control.

TextBox1.Text &= "Data1" & Environment.Newline
TextBox1.Text &= "Data2" & Environment.Newline

etc... Or:

TextBox1.AppendText("Data1" & Environment.Newline)
TextBox1.AppendText("Data2" & Environment.Newline)

I wouldnt' use + as in VB it implicitly assumes that your concatenating strings if it works for you, however if you have a variable with a number type, it's not going to concat it if you unfortunately have another number type beside it in the code line, unless you define the integer type for yourself over to a string so that it knows you want to "+" as a string, which therefore it will assume string concatenation for you.

Use "&" instead. Cheers :)

If a post helps you in any way or solves your particular issue, please remember to use the Propose As Answer option or Vote As Helpful
Visit the Forum: TechLifeForum


Friday, April 6, 2012 4:25 PM

put an & in front of the =, then put a CrLf at the end 

try this in an app with just a TextBox

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load        TextBox1.Multiline = True        TextBox1.Height = 200        Dim lstStr As New List(Of String)        lstStr = New String() {"cat", "dog", "horse", "pig", "cow", "bird"}.ToList        For Each s As String In lstStr            TextBox1.Text &= s & vbCrLf        Next    End Sub

“This forum post is my own opinion and does not necessarily reflect the opinion or view of Microsoft, its employees, or other MVPs.”


Saturday, April 7, 2012 12:49 AM

Try the AppendText function:
TextBox1.AppendText(clsDatRow.iFirstVal.ToString)
TextBox1.AppendText(" ROWS:")
TextBox1.AppendText(iCountRows.ToString & "  ")
TextBox1.AppendText(Date.Now.ToString & vbcrlf)

Saturday, April 7, 2012 1:55 AM

Hi Rudy68,

Try this:

TextBox1.Text = clsDatRow.iFirstVal.ToString & " ROWS:" & iCountRows.ToString & "  " & Date.Now.ToString & Environment.NewLine

Regards,


Saturday, April 7, 2012 3:24 AM

You are writing this code:

 TextBox1.Text = clsDatRow.iFirstVal.ToString + " ROWS:" + iCountRows.ToString + "  " + Date.Now.ToString

This code will clear all text in TextBox1 and fill it with code generated value.

Now if you want to keep the current text in TextBox1 and fill the new text in a new line then you need to write this code:

 TextBox1.Text =TextBox1.Text & vbcrlf & clsDatRow.iFirstVal.ToString + " ROWS:" + iCountRows.ToString + "  " + Date.Now.ToString

This will keep the current text and fill the new text in a new line.

Hope this helps.

If my post answers your question then mark as answer.


Sunday, April 8, 2012 1:11 PM

Thank everyone for the great suggestions!

Rudy