Newline in Text box

gary_ysh

New member
Joined
Mar 16, 2009
Messages
2
Programming Experience
Beginner
Dear All,

I have some challenges on the text box output..

I have textbox1, textbox2, command button1.

Textbox1 is the general console.
Textbox2 is the barcode field.
Commandbutton1 is the confirm button.

Scenario:

When scanner scaned a barcode, it will appear in the textbox2, when click on the commandbutton, it then add to the textbox1.

My problem is, when I scaned the second item, it can appear in the textbox2, but when I click on the commandbutton it then replace the previous item in the textbox1.

How can I make the textbox1 keeping all the record, and when everytime click on the commandbutton1, it appear in the next line in textbox1 rather than keep replacing the first data?

Thank you for helping.
 
VB.NET:
Dim newline as string =chr(13)+chr(10)

'or it could be

Dim newline as string = chr(10)+chr(13)

'I can never remember which, there is also a VB costant somewhere, I forget.

Textbox1.text= textbox1.text+new_line + textbox2.text
 
A newline alone will not do it. It will replace the previous text with a blank line and the new data.

You need to accumulate the new data and concatenate it to the old data. The newline constant is vbCrLf.


TextBox1.Text = TextBox1.Text & vbCrLf & newdata


or you can shorten the code as follows:


TextBox1.Text &= vbCrLf & newdata
 
A newline alone will not do it. It will replace the previous text with a blank line and the new data.

You need to accumulate the new data and concatenate it to the old data. The newline constant is vbCrLf.


TextBox1.Text = TextBox1.Text & vbCrLf & newdata


or you can shorten the code as follows:


TextBox1.Text &= vbCrLf & newdata
I advise against using the constants for two reasons: (1) They only work in vb and (2) there's no guarantee that they'll exist in future versions.

That being said you can just as easily do this: TextBox1.AppendText(Evironment.NewLine & NewData)
 
I have textbox1, textbox2, command button1.

Textbox1 is the general console.
Textbox2 is the barcode field.
Commandbutton1 is the confirm button.

So why didn't you call them:

consoleTextBox
barcodeTextBox
confirmButton


You ARE allowed to rename these things you know, and it really helps other developers understand your code/makes you look more professional

A newline alone will not do it. It will replace the previous text with a blank line and the new data.

Which is why use of the TextBox.AppendText() method should have been advocated.. It also appears to preserve any existing selection
 
Thank you Steve36445,

Your solution is work for partial as what I want, it can keep the old data, but it doesn't print the new data in next line.

After JuggaloBrotha's suggested to use
"environment.newline", it then can keep the old data, and print the new data in the next line.

cjard,

I will post it in more easy for understanable form next thread..
Thanks.

All,
Thank you for help, that is unexpected so much of friend giving help here!
 
Gary if I understand your original post correctly, Textbox1 is used only to keep a list of barcode items that were scanned. If this is correct, wouldnt you be better off using a listbox and entering a new item each time an item is scanned in TextBox2?

VB.NET:
Private Sub Button1_Click

    lstScannedItems.Items.Add(Textbox2.Text)

End Sub
 
Back
Top