Dim text1x As String
Dim Text2x As String
Dim Text3x As String
Dim aText() As String
Dim i As Integer
For i = 0 To List1.ListCount - 1
aText = Split(List1.List(i), " ")
On Error Resume Next
text1x = aText(0)
Text2x = aText(1)
If Text2x > 10 Then
List2.AddItem List1.List(i)
Frame3.Caption = List2.ListCount
End If
Next i
-----------------------------
The list1.listbox has items like this name<space>number:
andy 12
sam 13
jason 100
maria 200
Im trying to split the name and the number, and if the number is greater then 10, it adds to list2.
its not working out, its adding names under 10 and names over 10. i dont understand why. any suggestions.
If it were me when I do the compare I would use a CLng function to change the string to an integer
i.e. "If Text2x > 10 Then" I would change to "If CLng(Text2x) > 10 Then"
but like I said, I tried the code and it and it worked as you wanted it to.
Option Explicit
Private Sub Command1_Click()
'-------------------------
'The list1.listbox has items like this name<space>number:
With List1
.Clear
.AddItem "andy 12"
.AddItem "sam 13"
.AddItem "jason 100"
.AddItem "maria 200"
.AddItem "sam 3"
End With
End Sub
Private Sub Command2_Click()
Dim text1x As String
Dim Text2x As String
Dim Text3x As String
Dim aText() As String
Dim i As Integer
List2.Clear
For i = 0 To List1.ListCount - 1
aText = Split(List1.List(i), " ")
text1x = aText(0)
Text2x = aText(1)
If Text2x > 10 Then
List2.AddItem List1.List(i)
Frame3.Caption = List2.ListCount
End If
Next i
End Sub