Link to home
Start Free TrialLog in
Avatar of rjef
rjefFlag for United States of America

asked on

find out of sequence groups of numbers using vb6 in a listbox

i have a list of numbers that are in a listbox that have the same number 12 times and the last group will have 4 of the same number.  how do i figure out if they are in groups of 12 and then 4 .  also it would need to make sure the groups of numbers are sorted least to greatest
here is a test batch
 
10001000819
10001000819
10001000819
10001000819
10001000819
10001000819
10001000819
10001000819
10001000819
10001000819
10001000819
10001000820
10001000820
10001000820
10001000820
10001000820
10001000820
10001000820
10001000820
10001000820
10001000820
10001000820
10001000820
10001000820
10001000821
10001000821
10001000821
10001000821
10001000821
10001000821
10001000821
10001000821
10001000821
10001000821
10001000821
10001000821
10001000822
10001000822
10001000822
10001000822
10001000822
10001000822
10001000822
10001000822
10001000822
10001000822
10001000822
10001000822
10001000823
10001000823
10001000823
10001000823
10001000823

Avatar of Martin Liss
Martin Liss
Flag of United States of America image

The data you show doesn't seem to match your description; there are 11 of 10001000819 and 13 of 10001000821, so that's probably a typo, but there are 5 10001000823.

What do you want to do when you find that there's a group of 12 or 4?
Avatar of rjef

ASKER

yes --- so the vb program would need to identify this as not correct. it needs to look for 12 x 12 x 12 … x4 and if not  then highlight maybe the incorrect ones. or somehow id sequence out  of order.
here would be a correct one  (maybe)

10001000792
10001000792
10001000792
10001000792
10001000792
10001000792
10001000792
10001000792
10001000792
10001000792
10001000792
10001000792
10001000793
10001000793
10001000793
10001000793
10001000793
10001000793
10001000793
10001000793
10001000793
10001000793
10001000793
10001000793
10001000794
10001000794
10001000794
10001000794
10001000794
10001000794
10001000794
10001000794
10001000794
10001000794
10001000794
10001000794
10001000795
10001000795
10001000795
10001000795
Would a mixture of just 12s and 4s be correct?
Avatar of rjef

ASKER

no it would start off as 12 and stay 12 until 4. (4 at the end)
Avatar of rjef

ASKER

here is what a co-worker came up with in excel but i need it in vb

=IF(AND(A2<>A1,A2<>""),IF(A6<>"",IF(COUNTIF(A2:A13,A2)=12,"","Error"),IF(COUNTIF(A2:A5,A2)=4,"","Error")),"")
Try this code. Note that you should set List1's Sorted property to True in design mode.

Private Sub Command1_Click()
    Dim intIndex As Integer
    Dim strOld As String
    Dim intCount As Integer
    Dim strError As String
    
    strOld = List1.List(0)
    
    For intIndex = 0 To List1.ListCount - 1
        If List1.List(intIndex) = strOld Then
            intCount = intCount + 1
        Else
            If intCount = 12 Or intCount = 4 Then
                ' It's OK
            Else
                If strError = "" Then
                    strError = List1.List(intIndex - 1)
                Else
                    strError = strError & ", " & List1.List(intIndex - 1)
                End If
                intCount = 1
                strOld = List1.List(intIndex)
            End If
        End If
    Next
    
    ' Validate that the last 4 (and no more) are the same
    With List1
        If .List(.ListCount - 1) = .List(.ListCount - 2) And _
           .List(.ListCount - 1) = .List(.ListCount - 3) And _
           .List(.ListCount - 1) = .List(.ListCount - 4) And _
           .List(.ListCount - 1) <> .List(.ListCount - 5) Then
           ' OK
        Else
            If strError = "" Then
                strError = .List(.ListCount - 1)
            Else
                strError = strError & ", " & .List(.ListCount - 1)
            End If
        End If
    End With
    
    If strError = "" Then
        MsgBox "Valid List", , "List Validation"
    Else
        MsgBox "incorrect count found in " & strError, , "List Validation"
    End If
End Sub

Open in new window

SOLUTION
Avatar of aikimark
aikimark
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rjef

ASKER

it will always be 12 x 12 x 12 x …..  x 4
if not then that is considered an error  and the groups would always be together (if not then error)
My latest code should be OK then.