Results 1 to 6 of 6

Thread: Transferring Text box data to a list box

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2006
    Posts
    91

    Transferring Text box data to a list box

    I have a multilined text box, and i want to submit the data to a list box.

    problem is when i try to submit it using
    VB Code:
    1. List1.AddItem (Text1.Text)
    i get all of the data in the first entry of the list box... i watn each line to be submitted as a seperate list box entry.

    how do i do this?

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

    Re: Transferring Text box data to a list box

    VB Code:
    1. Dim sLines() As String, N As Long
    2.  
    3. sLines = Split(Text1.Text, vbCrLf)
    4. For N = 0 To UBound(sLines)
    5.     List1.AddItem sLines(N)
    6. Next N

  3. #3
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Transferring Text box data to a list box

    You don't need an array:
    VB Code:
    1. Dim N As Long
    2.     For N = 0 To UBound(Split(Text1.Text, vbCrLf))
    3.         List1.AddItem Split(Text1.Text, vbCrLf)(N)
    4.     Next N

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Oct 2006
    Posts
    91

    Re: Transferring Text box data to a list box

    awesome thanks guys

  5. #5

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

    Re: Transferring Text box data to a list box

    Quote Originally Posted by gavio
    You don't need an array:
    VB Code:
    1. Dim N As Long
    2.     For N = 0 To UBound(Split(Text1.Text, vbCrLf))
    3.         List1.AddItem Split(Text1.Text, vbCrLf)(N)
    4.     Next N
    gavio - that's terrible code - you say you don't need an array, but then you're using Number of lines + 1 of them - if there's 6 lines your code will create 7 arrays - create the array once and then read from it, don't constantly keep recreating that array - it makes the loop unneccesarily slow

    also, UBound(Split(Text1.Text, vbCrLf)) causes a memory leak.

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