|
-
Nov 23rd, 2006, 06:41 PM
#1
Thread Starter
Lively Member
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?
-
Nov 23rd, 2006, 06:44 PM
#2
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
-
Nov 23rd, 2006, 06:54 PM
#3
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
-
Nov 23rd, 2006, 07:05 PM
#4
Thread Starter
Lively Member
Re: Transferring Text box data to a list box
-
Nov 23rd, 2006, 07:20 PM
#5
Re: Transferring Text box data to a list box
No prob!
-
Nov 24th, 2006, 03:57 AM
#6
Re: Transferring Text box data to a list box
 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.
Last edited by bushmobile; Nov 24th, 2006 at 04:22 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|