Results 1 to 12 of 12

Thread: [RESOLVED] help with multiline textboxes

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    4

    Resolved [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

  2. #2
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: help with multiline textboxes

    Welcome to the Forum

    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:
    1. Text1.Text = "This is the first line" & vbcrlf
    2. Text1.SelStart = Len(Text1.Text)
    3. Text1.SelText = "This is another Line" & vbcrlf
    4. Text1.SelStart = Len(Text1.Text)
    5. Text1.SelText = "This is the third Line" & vbcrlf
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: help with multiline textboxes

    Welcome to the forums.

    Another way is
    VB Code:
    1. Text1.Text = Text1.Text & vbCrLf
    It all depends on which way works best for you.

  4. #4
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: help with multiline textboxes

    or just:

    VB Code:
    1. Text1.Text = "This is the first line"
    2.   Text1.Text = Text1.Text & vbCrLf & "This is another Line"
    3.   Text1.Text = Text1.Text & vbCrLf & "This is the third Line"

    Edit: too slow

  5. #5

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    4

    Smile 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

  6. #6

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    4

    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.

  7. #7
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    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:
    1. For i = 1 To 10
    2.   Text1.SelStart = Len(Text1.Text)
    3.   Text1.SelText = "line" & i & vbCrLf
    4. Next i

    PS: Use code tags when you post code.

    To insert Tabs use vbTab constant like this
    VB Code:
    1. Text1.Text = "Some Text" & vbtab & "More Text" & vbTab & "Some more here"
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  9. #9

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    4

    Re: help with multiline textboxes

    thanks, this works.
    So grateful this place exists.

    R. Jhilmit

  10. #10
    New Member
    Join Date
    Mar 2006
    Location
    Vidin
    Posts
    15

    Re: help with multiline textboxes

    Or you can do something like this:
    VB Code:
    1. For i = 1 To 10
    2. Text1.Text = Text1.Text & "Line No" & i & vbCrLf
    3. Next i

  11. #11
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  12. #12
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    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.
    Use [code] source code here[/code] tags when you post source code.

    My Articles

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width