Split an Array into several arrays

Hi all!

nowadays I have my mind in blank. :frowning: :frowning:

Has anyone needed to split an Array into several arrays?

For example:
I have an array with 200 or 300 strings(variable)

But I need to divide or split that elements into 20 arrays.
Any suggestions?
Thanks

Based upon what criteria?

for i=0 to Array0.ubound
select case i
case 0...19
 array1.append array0(i)
case 20...29
array2.append array0(i)
....
end Select
next i

like that?

well the only criteria will be if the number of elements are different to 20, then split to 20 arrays

Well, since Dave is a mind reader, he gave you the answer before you stated the criteria :slight_smile:

[quote=384663:@Dave S] for i=0 to Array0.ubound select case i case 0...19 array1.append array0(i) case 20...29 array2.append array0(i) .... end Select next i

like that?[/quote]
I think thats the idea, but the array sometimes have 300 sometimes 500 sometimes 1000.
I’ll gonna try to divide the number of elements to 20

dim x=ceil(array0.ubound/20)
for i=0 to Array0.ubound
select case i
case 0...x
 array1.append array0(i)
case x+1 to 2*x
array2.append array0(i)
....
case >= (19*x)+1
array20.append array0(i)
end Select
next i

may not be 100% syntax correct… but thats the idea.

It looks like I understand the goal differently. I think what he needs:

  • go from 1 array to 20
  • have between 200 and 300 elements in the 1 array, not exact number
  • create 20 arrays with same number of elements

Maybe it will work if you:

  • get a value of Array0.Ubound / 20
  • use the whole part (maybe add 1 to that)
  • do the for i=0 to Array0.Ubound and check if i / value is less than 1, then put that in array1, if it is 1.0 and less than 2, put in array2

Edit: Dave is fast answering and helping, thanks. I think is easier to look at his code than trying to make sense of what I wrote (even if they are the same idea)

another idea.

for i=0 to array0.ubound
indx=i mod 20
select case indx
case 0
array1.append array0(i)
case 1
array2.append array0(i)
....
case 19
array20.append array0(i)
end select
next i

[quote=384683:@Dave S]for i=0 to array0.ubound
indx=i mod 20
select case indx
case 0
array1.append array0(i)
case 1
array2.append array0(i)

case 19
array20.append array0(i)
end select
next i[/quote]
Men you are a Genius

So in this case the Main Array has 2,877 elements
and was spliced to the 20 arrays.

Or when the elements are lower than 20: