Click here to Skip to main content
15,936,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I Have 100 arrays (Columns1, Columns2, Columns3.... Columns100) where the number after "Columns" is variable.
I have for each array to do the same thing, 100 times again.
Is there a way that I can make a loop around my code (= the code that needs to run for each array) where i can make the name of the array variable, something like this:

VB
i = 1
Do until i = 100
    'with "Columns" & i
    '...some code
    'end with
Next


The purpose is that i can do my coding in a few lines, instead of copying the code 100 times and adapt the name of the arrays.

Thanks in advance!
Kevin
Posted
Updated 30-Oct-12 6:39am
v2
Comments
n.podbielski 30-Oct-12 11:31am    
You can refactor code that creates those 100 arrays.
You can create array of arrays and loop by that array.
But 1 thing you should do for sure: kick in the balls someone that created that code in the first place :)
kevin@uniac.be 30-Oct-12 12:58pm    
Thanks for your reply, but is it possible to set the name of an array in a variable, like in my example above?

Thanks again!
Kevin
Dave Kreskowiak 30-Oct-12 13:11pm    
No. If you need to do this, you're design is seriously flawed. You need to replace this Columnxxx garbage with a 2 dimensional array or some other structure.

Did it not occur to you that the Columnxxx stuff is itself an array??


1 solution

You can use a array like this:
VB
Dim Columns As Object()() = New Object(100 - 1)() {}
For i As Integer = 0 To 99
                ' now the current array is Columns(i)
		' now you can set the value of Columns(i)(...)
	Columns(i)(0) = "object1"
Next
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900