|
-
Jun 30th, 2006, 01:19 PM
#1
Thread Starter
Hyperactive Member
Split Function
I know how to use the split function... but I'm using it differently this time.. I want to be able to load a whole list in one listbox.. the format of what I am loading goes like this
aa - bb
cc - dd
ff - hh
and so on..
After that has been loaded, i want to click ONE button that will split the ENTIRE Listbox putting aa in List1 and bb in List2, cc in List1 and dd in List2, ff in List1 and hh in List2, and so on..
So, to summarize, i want to split an entire listbox into two listboxes splitting with a - , By pushing one button. Thanks
"Remember, remember the 5th of November, the gun powder treason and plot. I know of no reason why the gun powder treason should ever be forgot."
-
Jun 30th, 2006, 01:56 PM
#2
Addicted Member
Re: Split Function
Load the first listbox with all the info.. then do this.
VB Code:
Dim i as Integer
dim splitNum as Integer
For i = 0 to List1.ListCount - 1
splitNum = Instr(1, List1.List(i), "-", vbTextCompare) 'find the break
List2.AddItem Mid(List1.List(i), splitNum + 2) 'add the second part to the second list
List1.List(i) = Mid(List1.List(i), 1, splitNum - 2) 'rename the "aa - bb" to "aa"
Next i
-
Jun 30th, 2006, 02:01 PM
#3
Lively Member
Re: Split Function
Code:
Private Sub Command1_Click()
Dim MyStr As String
Dim MyArray() As String
Dim MyLoadArray() As String
Dim x&
ReDim MyArray(0 To (List1.ListCount - 1))
For x = 0 To List1.ListCount - 1
Debug.Print List1.List(x)
MyArray(x) = List1.List(x)
Next x
List1.Clear
List2.Clear
For x = 0 To UBound(MyArray())
ReDim MyLoadArray(0 To 1)
MyLoadArray() = Split(MyArray(x), " - ", 2, vbTextCompare)
List1.AddItem MyLoadArray(0)
List2.AddItem MyLoadArray(1)
Erase MyLoadArray()
Next
Erase MyArray()
End Sub
I'm sure there are more ways to do this, but this was the first way I thought of. Hope this helps!
-
Jun 30th, 2006, 02:01 PM
#4
Addicted Member
Re: Split Function
I really wish I had VB6 installed on this PC, so I can test some of this stuff. But I've looked that over several times, and it should work just fine.
-
Jun 30th, 2006, 02:10 PM
#5
Re: Split Function
VB Code:
Private Sub Command1_Click()
Dim tmp() As String
For x = 0 To List1.ListCount - 1
tmp = Split(List1.List(x), " - ")
List1.List(x) = tmp(0)
List2.AddItem tmp(1)
Next
End Sub
Private Sub Form_Load()
List1.AddItem "aa - bb"
List1.AddItem "cc - dd"
List1.AddItem "ee - ff"
List1.AddItem "gg - hh"
End Sub
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
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
|