Results 1 to 9 of 9

Thread: Multiline textbox

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2000
    Posts
    23
    How do implement a carriage return in a multiline textbox, so that everytime the users enter text it starts on a new line

  2. #2
    Guest
    At the end of each line add a 'vbCrLf'.
    Eg:
    Code:
    Text1.Text = "Hello World!" & vbCrLf
    Text1.Text = Text1.Text & "I'm going home!"
    If you didn't put the vbCrLf in there, the result would be:
    "Hello World!I'm going home!"
    But since we use vbCrLf the result is:
    "Hello World!
    I'm going home!"

    Hope it helps.

  3. #3
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    I think he wants to add the new lines when the user enters text, not when the code adds text. How are you going to define a point when a user starts to enter text? Is it every time the text box loses focus and gets it back again?

    Every time that event occurs, you can use this statement:
    Code:
    Text1.Text = Text1.Text & VbNewline
    That will add a new line to the end of the text.
    Harry.

    "From one thing, know ten thousand things."

  4. #4
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Private Sub Command1_Click()
    'if you use the focus event, everytime
    'you get focus you add a new blank line
    'the same with the button but I think the
    'button is the lesser evil

    Text1.SetFocus
    Text1.Text = Text1.Text & vbCrLf
    Text1.SelStart = Len(Text1.Text)
    '
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Aug 2000
    Posts
    23
    Thanks guys, but this is a textbox that allows the user to enter comments. So every time they start typing they should be on a new line. Should look something like this.
    boy
    girl
    child
    so on

  6. #6
    Guest
    The question is: When do you want it to go to a new line? Every word? Every time the textbox loses focus?

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Aug 2000
    Posts
    23
    It depends on the user, I don't know how long or short a comment could be.

  8. #8
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892
    I'm not sure what it is, either.
    But try this:
    Code:
    Private Sub Text1_GotFocus()
        If Not Right(Text1.Text, 2) = vbNewLine Then Text1.Text = Text1.Text & vbNewLine
        Text1.SelStart = Len(Text1.Text)
    End Sub

  9. #9
    Guest
    You could try using a listbox, Eg:
    Code:
    'LB1 is your listbox control
    'cmdAdd is a commandbutton to add a comment to the list.
    Private Sub cmdAdd_Click()
        Dim sResult As String
        sResult = InputBox("Please enter a comment:", "Add Comment", "")
        If sResult = "" Then Exit Sub
        LB1.AddItem sResult
    End Sub
    I hope this helps you, though I'm not sure exactly what you need.

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