Results 1 to 8 of 8

Thread: Multiline text boxes

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2007
    Posts
    21

    Multiline text boxes

    I have a mutiline text box on a form. I intend to use this box to display information as i loop through a dataset (so each new record will add new info to the text box)

    Thing is at certain points i want to have the text box move onto a new line. However i have no idea how i get VB to do this. I tried looking up anything i could about carridge returns and that in VB but found nothing of any help.

    Cna anybody tell me what code i would use to take a text box, and add new information onto a new line in that text box?

    Any help appreciated, thanks in advance.

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

    Re: Multiline text boxes

    There are two options:

    vbCrLf
    vbNewLine

    Both work, but without seeing the code you have, I can't tell you why they didn't work for you.

    Post what you have.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2007
    Posts
    21

    Re: Multiline text boxes

    Ok well the code im testing it with at the moment is nothing complex.

    Private Sub Form_Load()
    Text1.Text = "line1" + vbcr + "line 2" + vbcr + "line 3"
    End Sub

    The code for the project will be exactly the same in terms of the text box only the line1 line2 and line 3 will be replaced with variables (totals made from looping the dataset)

  4. #4

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Feb 2007
    Posts
    21

    Re: Multiline text boxes

    Ahhh ok vbNewLine seems to work. i hadnt found that before only vbcr and vbclf.

    And thanks for the tip on the + and the & might i ask though why & is better?

  6. #6
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Multiline text boxes

    + is overloaded and the operation (addition or concatenation) depends on the data types of the operands. If you intend to do concatenation, then by using & there is no ambiguity.

    vbCr wouldn't give you a new line, just resets cursor to start of line (Carriage Return). What you needed was Line Feed with vbLf. vbCrLf is a combination since usually for a new line of text you also need carriage return after doing a line feed (like what you did with typewriters in days gone by). vbNewline works similarly to vbCrLf, but I forgot the details regarding their differences if there are any.

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

    Re: Multiline text boxes

    Quote Originally Posted by flamereaper
    And thanks for the tip on the + and the & might i ask though why & is better?
    Fundamentally VB, and most programming languages, treat + as the sign for addition as opposed to concantenation.

    It can, and often does, work but that is not what it was designed to do and therefore, could cause problems that would be a complete bugger to figure out.

    Use + when you want to add some numbers and & when you want to contanate strings.

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

    Re: Multiline text boxes

    Quote Originally Posted by leinad31
    vbNewline works similarly to vbCrLf, but I forgot the details regarding their differences if there are any.
    vbCrLf is always CR+LF whereas vbNewLine is platform specific. Whilst that might not mean anything in terms of VB6, the vbNewLine constant is part of the VBA library, so in Word for Mac, for example, it may not represent both CR and LF.

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