for j as integer = 0 to 5
select case j
case 0
FX.sortwith(name, level)
for i as integer = 0 to name.lastIndex
if FX(i) > 0 then addToPrintArray name(i), level(i), j, i, competition
next i
case 1
PH.sortwith(name, level)
for i as integer = 0 to name.lastIndex
if PH(i) > 0 then addToPrintArray name(i), level(i), j, i, competition
next i
case 2
SR.sortwith(name, level)
for i as integer = 0 to name.lastIndex
if SR(i) > 0 then addToPrintArray name(i), level(i), j, i, competition
next i
case 3
VT.sortwith(name, level)
for i as integer = 0 to name.lastIndex
if VT(i) > 0 then addToPrintArray name(i), level(i), j, i, competition
next i
case 4
PB.sortwith(name, level)
for i as integer = 0 to name.lastIndex
if PB(i) > 0 then addToPrintArray name(i), level(i), j, i, competition
next i
case 5
HB.sortwith(name, level)
for i as integer = 0 to name.lastIndex
if HB(i) > 0 then addToPrintArray name(i), level(i), j, i, competition
next i
end select
Var FX() As Integer = Array(1, 2, 3)
Var PH() As Integer = Array(4, 5, 6)
Var SR() As Integer = Array(7, 8, 9)
Var variantArray() As Variant
variantArray.Add FX
variantArray.Add PH
variantArray.Add SR
For Each v As Variant In variantArray
Var currentArray() As Integer = v
For Each i As Integer In currentArray
// Your code here
Next
Next
If you have problems like that then you usually have a code smell and it’s time for a refactor. Like make a class out of the arrays. But it really depends on what you are doing with the arrays. Perhaps you need an interface or an iterator.
You can create a method that get the array as argument
Like:
//name, level and competion exist in the same scope otherwise you have to pass them as arguments
sub sortAndCheck(values() as integer, j as integer)
values.sortWith(name, level)
for i as integer=0 to name.lastIndex //you should check that values and name have the same count
if values(i)>0 then addToPrintArray name(i), level(i), j, i, competition
next
end sub
//you can call directly
sortAndCheck FX, 0
sortAndCheck PH, 1
// and so on
//or use the case solution
for j as integer=0 to 5
var toCheck() as integer
toCheck=nil
select case j
case 0
toCheck=FX
case 1
toCheck=PH
//....
end select
if toSort<>nil then //just to avoid a missing case
sortAndCheck toSort, j
end if
next