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:
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?
Re: Transferring Text box data to a list box
VB Code:
Dim sLines() As String, N As Long
sLines = Split(Text1.Text, vbCrLf)
For N = 0 To UBound(sLines)
List1.AddItem sLines(N)
Next N
Re: Transferring Text box data to a list box
You don't need an array:
VB Code:
Dim N As Long
For N = 0 To UBound(Split(Text1.Text, vbCrLf))
List1.AddItem Split(Text1.Text, vbCrLf)(N)
Next N
Re: Transferring Text box data to a list box
Re: Transferring Text box data to a list box
Re: Transferring Text box data to a list box
Quote:
Originally Posted by gavio
You don't need an array:
VB Code:
Dim N As Long
For N = 0 To UBound(Split(Text1.Text, vbCrLf))
List1.AddItem Split(Text1.Text, vbCrLf)(N)
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.