Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

can you call an array with a variable name

Status
Not open for further replies.

jrice174

Civil/Environmental
Nov 8, 2004
129
0
0
US
If I am making a sub or function to perform a task with an array, can I call the array with a generic name so I don't have to rewrite the routine for each different array name? Forinstance, if I had ArrayA and ArrayB and wanted to change the first instance in each array to 4

strArrayName = "ArrayA"
Call ArrayRoutine
strArrayName = "ArrayB"
Call ArrayRoutine

sub ArrayRoutine()
strArrayName(0) = 4
end sub
 
Replies continue below

Recommended for you

You can do indrect addressing in VB, either by creating Shell Script objects or by using the Eval function. However, based on your situation, it seems far simpler to pass the array as a parameter by reference.

Call ArrayRoutine (ArrayA)
Call ArrayRoutine (ArrayB)

Sub ArrayRoutine (TheArray)
TheArray(0) = 4
End Sub



Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Thanks so much for the tip. I'm constantly amazed at how a problem that seems so hard at the time can have such a simple solution.
 
I thought I had it, but I still can't make it work. I'm using VBA within AutoCAD but I don't think that makes a difference. I get an error message that says ArrayA is not defined. Should it be a double like the array, a string because it's a name or something else? Do I need to use the Set keyword?
 
I'm sorry, the actual syntax would be as follows:

Dim ArrayA(5) As Integer
Dim ArrayB(5) as Integer

Call ProcArray(ArrayA())
Call ProcArray(Arrayb())

---

Sub ProcArray(TheArray() As Integer)
End Sub

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Status
Not open for further replies.
Back
Top