Solved

Whats wrong with my code! its not working 500 Points.

Posted on 2004-08-19
4
159 Views
Last Modified: 2010-05-02
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.
0
Comment
Question by:andyakira
  • 2
4 Comments
 
LVL 15

Expert Comment

by:Colosseo
ID: 11846888
Hi

I tried your code with an entry of sam 9 and it didnt add to the listbox so your code seems to work for me.

maybe you could try If CInt(Text2x) > 10 Then

this should make sure that Text2x is an integer for the comparison

HTH

Scott
0
 
LVL 18

Accepted Solution

by:
JR2003 earned 500 total points
ID: 11846928
I tried this and it worked fine. So I'm not sure why yours is not working.
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

0
 

Author Comment

by:andyakira
ID: 11846983
it works for smaller lists, im using a list with 2000 names. it messes up.
0
 

Author Comment

by:andyakira
ID: 11847021
yours worked, it looks the same as the code i was using.. i dont get it :D
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
to transfer string from C lanaguage to VBA 4 56
Windows Script Host failed (Access is denied.) error 6 100
Spell Check in VB6 13 95
Set email body to html using vbscript 6 22
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

939 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now