Link to home
Start Free TrialLog in
Avatar of isnoend2001
isnoend2001Flag for United States of America

asked on

modify some vb6 array code

I have some vb6 code that loops thru saved file and loads the filenames in a combobox
problem is some may exist and others not
Example filenames
9-20-2015.rtf
9-21-2015.rtf
9-25-2015.rtf
Yr9-20-2015.rtf
Yr10-25-2016.rtf
Dy1000.rtf
Wk10-25-2016.rtf
Mo10-25-2016.rtf
Yr10-25-2016.rtf
Wk10-25-2016.rtf
10-22-2016.rtf
10-21-2016.rtf
11-25-2016.rtf
Yr9-20-2016.rtf
Yr10-25-2016.rtf
Dy10-25-2016.rtf
Wk3-25-2016.rtf
Mo10-25-2016.rtf
Yr5-25-2016.rtf
Wk9-25-2016.rtf
Dy0630.rtf
Dy0900.rtf
Wk10-25-2016.rtf
Yr10-25-2016.rtf
Wk10-25-2016.rtf


Sub FillArrays()
Dim lngIndex As Long
If cboTasks.ListCount = 0 Then Exit Sub'first use will be empty
' Initialize the arrays
ReDim gArrDaily(0)  'example entry Da9-30-2015.rtf
ReDim gArrWeekly(0) 'example entry Wk9-30-2015.rtf
ReDim gArrMonthly(0) 'example entry Mo9-30-2015.rtf
ReDim gArrYearly(0) 'example entry Yr9-30-2015.rtf
ReDim gArrNoRepeat(0) 'example entry 9-30-2015.rtf


    ' Loop through the combox entries looking for a two-
    ' character identifier
    For lngIndex = 0 To cboTasks.ListCount - 1
        Select Case UCase(Left$(cboTasks.List(lngIndex), 2))
            Case "DY"
                ' Add the item to the mArrDaily array and increase
                ' the size of the array by 1 in preparation for
                ' the next entry
               gArrDaily(UBound(gArrDaily)) = cboTasks.List(lngIndex)
                ReDim Preserve gArrDaily(UBound(gArrDaily) + 1)
            Case "WK"
                gArrWeekly(UBound(gArrWeekly)) = cboTasks.List(lngIndex)
                ReDim Preserve gArrWeekly(UBound(gArrWeekly) + 1)
            Case "MO"
                gArrMonthly(UBound(gArrMonthly)) = cboTasks.List(lngIndex)
                ReDim Preserve gArrMonthly(UBound(gArrMonthly) + 1)
            Case "YR"
                gArrYearly(UBound(gArrYearly)) = cboTasks.List(lngIndex)
                ReDim Preserve gArrYearly(UBound(gArrYearly) + 1)
            Case Else
                gArrNoRepeat(UBound(gArrNoRepeat)) = cboTasks.List(lngIndex)
                ReDim Preserve gArrNoRepeat(UBound(gArrNoRepeat) + 1)
               
        End Select
    Next
    ' The "preparation for the next entry" leaves an empty
    ' array entry so get rid of them.
    ReDim Preserve gArrDaily(UBound(gArrDaily) - 1)
    ReDim Preserve gArrWeekly(UBound(gArrWeekly) - 1)
    ReDim Preserve gArrMonthly(UBound(gArrMonthly) - 1)
    ReDim Preserve gArrYearly(UBound(gArrYearly) - 1)
    ReDim Preserve gArrNoRepeat(UBound(gArrNoRepeat) - 1)
'End With
End Sub
How to write this in case some are not in the cbo ?
ASKER CERTIFIED SOLUTION
Avatar of Martin Liss
Martin Liss
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
Avatar of isnoend2001

ASKER

Wil lthat work even if some are missing ?
Try it:)