[RESOLVED] help with multiline textboxes
hi,
I'm an engineer who dabbles in programming and i need some help from you all the experts, I need to know how to output several lines into a textbox. what i need to have is a heading, and then several lines (actual no. depending on the user inputs) in one textbox. each line comes from a pass through a loop.
Thanks.
R. Jhilmit
Re: help with multiline textboxes
Welcome to the Forum :wave:
Set the multiline property of the textbox to true.
Set the Scrollbars property to 3-Both.
And whenever you add a line of text to the text box, append it with vbcrlf. Something like this
VB Code:
Text1.Text = "This is the first line" & vbcrlf
Text1.SelStart = Len(Text1.Text)
Text1.SelText = "This is another Line" & vbcrlf
Text1.SelStart = Len(Text1.Text)
Text1.SelText = "This is the third Line" & vbcrlf
Re: help with multiline textboxes
Welcome to the forums. :wave:
Another way is
VB Code:
Text1.Text = Text1.Text & vbCrLf
It all depends on which way works best for you.
Re: help with multiline textboxes
or just:
VB Code:
Text1.Text = "This is the first line"
Text1.Text = Text1.Text & vbCrLf & "This is another Line"
Text1.Text = Text1.Text & vbCrLf & "This is the third Line"
Edit: too slow :cry:
Re: help with multiline textboxes
thanks,
but when i try to implement this in a for loop i only get the 1st line.
For i = 1 To 10
Text1.SelStart = Len(Text1.Text)
Text1.Text = "line" & i & vbCrLf
Next i
i want this to ouput something like
line1
line2
line3
.
.
.
line10
but all it does is show me line10. how can i fix this?
Thanks
R. jhilmit
Re: help with multiline textboxes
Thanks a whole bunch, the 2nd way works the way i need it to, that is text1.text = text1.text & "". One last question, is there anyway of entering a tab so that the columns are evenly spaced?
thanks.
Re: help with multiline textboxes
When you use .Text you are replacing the whole text, if you look at my example I am using SelText, so your code should be like this
VB Code:
For i = 1 To 10
Text1.SelStart = Len(Text1.Text)
Text1.SelText = "line" & i & vbCrLf
Next i
PS: Use code tags when you post code.
To insert Tabs use vbTab constant like this
VB Code:
Text1.Text = "Some Text" & vbtab & "More Text" & vbTab & "Some more here"
Re: help with multiline textboxes
Quote:
Originally Posted by thetruedarknight
Thanks a whole bunch, the 2nd way works the way i need it to, that is text1.text = text1.text & "". One last question, is there anyway of entering a tab so that the columns are evenly spaced?
thanks.
You are dealing with a textbox, not ListView. Even spacing in a free form textbox would require knowing the exact length of whatever will be the longest line + 2 then tabbing that number of spaces after the length of each line minus that length against the longest.
Re: help with multiline textboxes
thanks, this works.
So grateful this place exists.
R. Jhilmit
Re: help with multiline textboxes
Or you can do something like this:
VB Code:
For i = 1 To 10
Text1.Text = Text1.Text & "Line No" & i & vbCrLf
Next i
Re: help with multiline textboxes
Quote:
Originally Posted by thetruedarknight
thanks, this works.
So grateful this place exists.
R. Jhilmit
If this is resolved, please pull down the Thread Tools menu and click the Mark Thread Resolved button. That will let everyone know that you have your answer.
Thank you. :)
Re: help with multiline textboxes
Quote:
Originally Posted by thetruedarknight
thanks, this works.
So grateful this place exists.
R. Jhilmit
--removed content-- already posted in previous thread by Hack.
@Hack: I thought I will post this first and I even did, but you are too quick in spamming. :bigyello: