calculating and adding a range to a collection

M

marola20

Ok, this one might take me a minute to explain.
I'm trying to capture a list of numbers (mostly)...and add them to
collection. My test "string" is:
1001, 1003, 1005-1007, 1008, 1009, 1010-1019, 1022

I am able to add the individual numbers "1001" just fine. What I don
know how to do is calculate and add the ranges "1005-1007."
To make matters worse, the nubmers and ranges can begin with a letter.
I'm not so concerned with getting an answer on the leading lette
problem, but a nudge in the right direction on calculating the rang
would be great.

Thanks, M
 
B

Bob Phillips

Hi Marola,

Firstly use Split to split it into an array with the - as the split
character (assuming that you have already stripped the alphas).

Then do a simple loop on these 2 numbers adding to the collection

For i = aryNums(0) to aryNums(1)
myColl.Add Cstr(i),Cstr(i)
Next i

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Top