Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing mulitple lines in Text Box 1

Status
Not open for further replies.

CWebster

Programmer
Jun 12, 2002
38
GB
OK, this should be simple and I know I'll let out a loud "D'oh!" when I see the answer, but here goes anyhow....

Using VB6 I created two forms. Form1 collects names entered via a text box and saves them to a file. Form2 loads the contents of the file into an array then -should- print the contents into a textbox.

I can print into a listBox with no trouble but all I get when I try to print to the TextBox is the last name in the file. In the design side of things, I've enabled the Multiline property of the TextBox.

I don't have the code here, but I #think# this is the loop I used to print into the textbox:

For counter = 1 to 6
txtTextBox.Text = TextArray(counter)
vbNewLine
Next counter

Thanks in advamce...
 
Hi,

In the loop you set the entire text of txtTextBox to the values of TextArray(count). That means last thing that happens is that the text is set to TextArray(6).
You could fix that by:
------------------------------------------------------
txtTextBox.Text = ""
For counter = 1 to 6
txtTextBox.Text = txtTextBox.Text & TextArray(counter)
vbNewLine
Next counter
------------------------------------------------------
That is however very inefficient, this is better:
------------------------------------------------------
txttextbox.text = join(TextArray,VbCrLf)
------------------------------------------------------

Is have an even faster way to add the text from an array to a string, but is is ridiculously complicated, and probabply not relevant here... Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
Hi,

Here is a discussion of diffent methods to add text to a textbox: thread222-258553

Thx for the star [pipe] Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top