copy combo items to 5 arrays using vb6

am trying to add combox items to 5 arrays  based on the names
form level arraysi
Dim mArrDaily()  'example entry Da9-30-2015.rtf
Dim mArrWeekly() 'example entry Wk9-30-2015.rtf
Dim mArrMonthly() 'example entry Mo9-30-2015.rtf
Dim mArrYearly() 'example entry Yr9-30-2015.rtf
Dim mArrNoRepeat() 'example entry 9-30-2015.rtf

Private Sub Form_Load()
With cboTest
.AddItem "9-20-2015.rtf" ' add to mArrNoRepeat
.AddItem "9-21-2015.rtf" ' add to mArrNoRepeat
.AddItem "9-25-2015.rtf" ' add to mArrNoRepeat
.AddItem "Yr9-20-2015.rtf" ' add to mArrYearly
.AddItem "Yr10-25-2016.rtf" ' add to mArrYearly
.AddItem "Dy1000.rtf" 'mstrDaly at 10AM
.AddItem "Wk10-25-2016.rtf" 'add to mArrWeekly
.AddItem "Mo10-25-2016.rtf" 'add to mArrMonthly
.AddItem "Yr10-25-2016.rtf" ' add to mArrYearly
.AddItem "Wk10-25-2016.rtf" 'add to mArrMonthly
.AddItem "10-22-2016.rtf" ' add to mArrNoRepeat
.AddItem "10-21-2016.rtf" ' add to mArrNoRepeat
.AddItem "11-25-2016.rtf" ' add to mArrNoRepeat
.AddItem "Yr9-20-2016.rtf" 'add to mArrWeekly
.AddItem "Yr10-25-2016.rtf" 'add to mArrWeekly
.AddItem "Dy10-25-2016.rtf" 'add to mstrDaly
.AddItem "Wk3-25-2016.rtf" 'add to mArrWeekly
.AddItem "Mo10-25-2016.rtf" 'add to mArrMonthly
.AddItem "Yr5-25-2016.rtf" ' add to mArrYearly
.AddItem "Wk9-25-2016.rtf" 'add to mArrWeekly
.AddItem "Dy0630.rtf" 'mstrDaly at 6:30AM
.AddItem "Dy0900.rtf" 'mstrDaly at 9:00AM
.AddItem "Wk10-25-2016.rtf" 'add to mArrMonthly
.AddItem "Yr10-25-2016.rtf" ' add to mArrYearly
.AddItem "Wk10-25-2016.rtf" 'add to mArrMonthly

End With
End Sub

Open in new window

I need the arrays to be used in other code
how can this be done?
isnoend2001Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
The following assumes that you add the data to cboTest by way of a command button named Command1. With the arrays defined at the top of the form's code, they will be available everywhere in the form. Note that while Dim works you should use Private instead. If you have more modules and you want the arrays available everywhere, move them to a code module, make them Public (and I would change the mArr... to gArr...).

Option Explicit
Dim mArrDaily()  'example entry Da9-30-2015.rtf
Dim mArrWeekly() 'example entry Wk9-30-2015.rtf
Dim mArrMonthly() 'example entry Mo9-30-2015.rtf
Dim mArrYearly() 'example entry Yr9-30-2015.rtf
Dim mArrNoRepeat() 'example entry 9-30-2015.rtf

Private Sub Command1_Click()
Dim lngIndex As Long

' Initialize the arrays
ReDim mArrDaily(0)  'example entry Da9-30-2015.rtf
ReDim mArrWeekly(0) 'example entry Wk9-30-2015.rtf
ReDim mArrMonthly(0) 'example entry Mo9-30-2015.rtf
ReDim mArrYearly(0) 'example entry Yr9-30-2015.rtf
ReDim mArrNoRepeat(0) 'example entry 9-30-2015.rtf
With cboTest
    .Clear
    .AddItem "9-20-2015.rtf" ' add to mArrNoRepeat
    .AddItem "9-21-2015.rtf" ' add to mArrNoRepeat
    .AddItem "9-25-2015.rtf" ' add to mArrNoRepeat
    .AddItem "Yr9-20-2015.rtf" ' add to mArrYearly
    .AddItem "Yr10-25-2016.rtf" ' add to mArrYearly
    .AddItem "Dy1000.rtf" 'mstrDaly at 10AM
    .AddItem "Wk10-25-2016.rtf" 'add to mArrWeekly
    .AddItem "Mo10-25-2016.rtf" 'add to mArrMonthly
    .AddItem "Yr10-25-2016.rtf" ' add to mArrYearly
    .AddItem "Wk10-25-2016.rtf" 'add to mArrMonthly
    .AddItem "10-22-2016.rtf" ' add to mArrNoRepeat
    .AddItem "10-21-2016.rtf" ' add to mArrNoRepeat
    .AddItem "11-25-2016.rtf" ' add to mArrNoRepeat
    .AddItem "Yr9-20-2016.rtf" 'add to mArrWeekly
    .AddItem "Yr10-25-2016.rtf" 'add to mArrWeekly
    .AddItem "Dy10-25-2016.rtf" 'add to mstrDaly
    .AddItem "Wk3-25-2016.rtf" 'add to mArrWeekly
    .AddItem "Mo10-25-2016.rtf" 'add to mArrMonthly
    .AddItem "Yr5-25-2016.rtf" ' add to mArrYearly
    .AddItem "Wk9-25-2016.rtf" 'add to mArrWeekly
    .AddItem "Dy0630.rtf" 'mstrDaly at 6:30AM
    .AddItem "Dy0900.rtf" 'mstrDaly at 9:00AM
    .AddItem "Wk10-25-2016.rtf" 'add to mArrMonthly
    .AddItem "Yr10-25-2016.rtf" ' add to mArrYearly
    .AddItem "Wk10-25-2016.rtf" 'add to mArrMonthly

    ' Loop through the combox entries looking for a two-
    ' character identifier
    For lngIndex = 0 To cboTest.ListCount - 1
        Select Case UCase(Left$(cboTest.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
                mArrDaily(UBound(mArrDaily)) = cboTest.List(lngIndex)
                ReDim Preserve mArrDaily(UBound(mArrDaily) + 1)
            Case "WK"
                mArrWeekly(UBound(mArrWeekly)) = cboTest.List(lngIndex)
                ReDim Preserve mArrWeekly(UBound(mArrWeekly) + 1)
            Case "MO"
                mArrDaily(UBound(mArrMonthly)) = cboTest.List(lngIndex)
                ReDim Preserve mArrMonthly(UBound(mArrMonthly) + 1)
            Case "YR"
                mArrDaily(UBound(mArrYearly)) = cboTest.List(lngIndex)
                ReDim Preserve mArrYearly(UBound(mArrYearly) + 1)
            Case Else
                mArrDaily(UBound(mArrNoRepeat)) = cboTest.List(lngIndex)
                ReDim Preserve mArrNoRepeat(UBound(mArrNoRepeat) + 1)
        End Select
    Next
    ' The "preparation for the next entry" leaves an empty
    ' array entry so get rid of them.
    ReDim Preserve mArrDaily(UBound(mArrDaily) - 1)
    ReDim Preserve mArrWeekly(UBound(mArrWeekly) - 1)
    ReDim Preserve mArrMonthly(UBound(mArrMonthly) - 1)
    ReDim Preserve mArrYearly(UBound(mArrYearly) - 1)
    ReDim Preserve mArrNoRepeat(UBound(mArrNoRepeat) - 1)
End With
End Sub

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
isnoend2001Author Commented:
thanks Marty;
getting an error here:
 Case Else
                mArrDaily(UBound(mArrNoRepeat)) = cboTest.List(lngIndex)
                ReDim Preserve mArrNoRepeat(UBound(mArrNoRepeat) + 1)

"SubScrrt out of range"
Martin LissOlder than dirtCommented:
mArrNoRepeat(UBound(mArrNoRepeat)) = cboTest.List(lngIndex)
                ReDim Preserve mArrNoRepeat(UBound(mArrNoRepeat) + 1)
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Martin LissOlder than dirtCommented:
I'm reposting the code because the same typo was other places.

Option Explicit
Dim mArrDaily()  'example entry Da9-30-2015.rtf
Dim mArrWeekly() 'example entry Wk9-30-2015.rtf
Dim mArrMonthly() 'example entry Mo9-30-2015.rtf
Dim mArrYearly() 'example entry Yr9-30-2015.rtf
Dim mArrNoRepeat() 'example entry 9-30-2015.rtf

Private Sub Command1_Click()
Dim lngIndex As Long

' Initialize the arrays
ReDim mArrDaily(0)  'example entry Da9-30-2015.rtf
ReDim mArrWeekly(0) 'example entry Wk9-30-2015.rtf
ReDim mArrMonthly(0) 'example entry Mo9-30-2015.rtf
ReDim mArrYearly(0) 'example entry Yr9-30-2015.rtf
ReDim mArrNoRepeat(0) 'example entry 9-30-2015.rtf
With cboTest
    .Clear
    .AddItem "9-20-2015.rtf" ' add to mArrNoRepeat
    .AddItem "9-21-2015.rtf" ' add to mArrNoRepeat
    .AddItem "9-25-2015.rtf" ' add to mArrNoRepeat
    .AddItem "Yr9-20-2015.rtf" ' add to mArrYearly
    .AddItem "Yr10-25-2016.rtf" ' add to mArrYearly
    .AddItem "Dy1000.rtf" 'mstrDaly at 10AM
    .AddItem "Wk10-25-2016.rtf" 'add to mArrWeekly
    .AddItem "Mo10-25-2016.rtf" 'add to mArrMonthly
    .AddItem "Yr10-25-2016.rtf" ' add to mArrYearly
    .AddItem "Wk10-25-2016.rtf" 'add to mArrMonthly
    .AddItem "10-22-2016.rtf" ' add to mArrNoRepeat
    .AddItem "10-21-2016.rtf" ' add to mArrNoRepeat
    .AddItem "11-25-2016.rtf" ' add to mArrNoRepeat
    .AddItem "Yr9-20-2016.rtf" 'add to mArrWeekly
    .AddItem "Yr10-25-2016.rtf" 'add to mArrWeekly
    .AddItem "Dy10-25-2016.rtf" 'add to mstrDaly
    .AddItem "Wk3-25-2016.rtf" 'add to mArrWeekly
    .AddItem "Mo10-25-2016.rtf" 'add to mArrMonthly
    .AddItem "Yr5-25-2016.rtf" ' add to mArrYearly
    .AddItem "Wk9-25-2016.rtf" 'add to mArrWeekly
    .AddItem "Dy0630.rtf" 'mstrDaly at 6:30AM
    .AddItem "Dy0900.rtf" 'mstrDaly at 9:00AM
    .AddItem "Wk10-25-2016.rtf" 'add to mArrMonthly
    .AddItem "Yr10-25-2016.rtf" ' add to mArrYearly
    .AddItem "Wk10-25-2016.rtf" 'add to mArrMonthly

    ' Loop through the combox entries looking for a two-
    ' character identifier
    For lngIndex = 0 To cboTest.ListCount - 1
        Select Case UCase(Left$(cboTest.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
                mArrDaily(UBound(mArrDaily)) = cboTest.List(lngIndex)
                ReDim Preserve mArrDaily(UBound(mArrDaily) + 1)
            Case "WK"
                mArrWeekly(UBound(mArrWeekly)) = cboTest.List(lngIndex)
                ReDim Preserve mArrWeekly(UBound(mArrWeekly) + 1)
            Case "MO"
                mArrMonthly(UBound(mArrMonthly)) = cboTest.List(lngIndex)
                ReDim Preserve mArrMonthly(UBound(mArrMonthly) + 1)
            Case "YR"
                mArrYearly(UBound(mArrYearly)) = cboTest.List(lngIndex)
                ReDim Preserve mArrYearly(UBound(mArrYearly) + 1)
            Case Else
                mArrNoRepeat(UBound(mArrNoRepeat)) = cboTest.List(lngIndex)
                ReDim Preserve mArrNoRepeat(UBound(mArrNoRepeat) + 1)
        End Select
    Next
    ' The "preparation for the next entry" leaves an empty
    ' array entry so get rid of them.
    ReDim Preserve mArrDaily(UBound(mArrDaily) - 1)
    ReDim Preserve mArrWeekly(UBound(mArrWeekly) - 1)
    ReDim Preserve mArrMonthly(UBound(mArrMonthly) - 1)
    ReDim Preserve mArrYearly(UBound(mArrYearly) - 1)
    ReDim Preserve mArrNoRepeat(UBound(mArrNoRepeat) - 1)
End With
End Sub

Open in new window

isnoend2001Author Commented:
Thanks
i don't understand this part:
  ' The "preparation for the next entry" leaves an empty
    ' array entry so get rid of them.
    ReDim Preserve mArrDaily(UBound(mArrDaily) - 1)
    ReDim Preserve mArrWeekly(UBound(mArrWeekly) - 1)
    ReDim Preserve mArrMonthly(UBound(mArrMonthly) - 1)
    ReDim Preserve mArrYearly(UBound(mArrYearly) - 1)
    ReDim Preserve mArrNoRepeat(UBound(mArrNoRepeat) - 1)
Martin LissOlder than dirtCommented:
OK tell me if this helps.

By defining an array like Dim mArrDaily() rather than something like Dim mArrDaily(6) you've defined a dynamic array rather than the latter one which would be a fixed array with 7 entries (that 0 through 6 which = 7). A dynamic array can't be used however until it has an entry so initially I gave them one with ReDim mArrDaily(0). Note that that entry is empty. Redim redimensions (same as saying changes the number of entries) arrays but unless you use Redim Preserve the contents of the array is emptied.

So in line 53 above we have mArrDaily(UBound(mArrDaily)) = cboTest.List(lngIndex). UBound(mArrDaily) returns the upper boundry of the array which at first because of line 12 is zero so line 53 the first time through is the same as mArrDaily(0) = cboTest.List(lngIndex) so the first cboTest value gets added to mArrDaily(0).

Using the key word Preserve, line 54 increases the size the array by one and the first time through it's the same as  ReDim Preserve mArrDaily (0 + 1) which of course is the same as  ReDim Preserve mArrDaily (1). Note however that the new mArrDaily(1) entry is empty and that each time one of the cboTest values is added to the array an empty entry below it is created.

If we did nothing else, mArrDaily would wind up looking like
Entry 0 = Dy1000.rtf
Entry 1 = Dy10-25-2016.rtf
Entry 2 = Dy0630.rtf
Entry 3 = Dy0900.rtf
Entry 4 =

If you are aware of the blank entry you can code around anytime you refer to the array anywhere else, it but it's easier to just remove it here by Redim Preserve-ing it one smaller rather than one larger as line 54, and that's what lines 71 to 75 do.
isnoend2001Author Commented:
i see thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.