isnoend2001
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(gArrWeek ly)) = cboTasks.List(lngIndex)
ReDim Preserve gArrWeekly(UBound(gArrWeek ly) + 1)
Case "MO"
gArrMonthly(UBound(gArrMon thly)) = cboTasks.List(lngIndex)
ReDim Preserve gArrMonthly(UBound(gArrMon thly) + 1)
Case "YR"
gArrYearly(UBound(gArrYear ly)) = cboTasks.List(lngIndex)
ReDim Preserve gArrYearly(UBound(gArrYear ly) + 1)
Case Else
gArrNoRepeat(UBound(gArrNo Repeat)) = cboTasks.List(lngIndex)
ReDim Preserve gArrNoRepeat(UBound(gArrNo Repeat) + 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(gArrWeek ly) - 1)
ReDim Preserve gArrMonthly(UBound(gArrMon thly) - 1)
ReDim Preserve gArrYearly(UBound(gArrYear ly) - 1)
ReDim Preserve gArrNoRepeat(UBound(gArrNo Repeat) - 1)
'End With
End Sub
How to write this in case some are not in the cbo ?
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(
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
ReDim Preserve gArrDaily(UBound(gArrDaily
Case "WK"
gArrWeekly(UBound(gArrWeek
ReDim Preserve gArrWeekly(UBound(gArrWeek
Case "MO"
gArrMonthly(UBound(gArrMon
ReDim Preserve gArrMonthly(UBound(gArrMon
Case "YR"
gArrYearly(UBound(gArrYear
ReDim Preserve gArrYearly(UBound(gArrYear
Case Else
gArrNoRepeat(UBound(gArrNo
ReDim Preserve gArrNoRepeat(UBound(gArrNo
End Select
Next
' The "preparation for the next entry" leaves an empty
' array entry so get rid of them.
ReDim Preserve gArrDaily(UBound(gArrDaily
ReDim Preserve gArrWeekly(UBound(gArrWeek
ReDim Preserve gArrMonthly(UBound(gArrMon
ReDim Preserve gArrYearly(UBound(gArrYear
ReDim Preserve gArrNoRepeat(UBound(gArrNo
'End With
End Sub
How to write this in case some are not in the cbo ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try it:)
ASKER