×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

can you call an array with a variable name

can you call an array with a variable name

can you call an array with a variable name

(OP)
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

RE: can you call an array with a variable name

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

RE: can you call an array with a variable name

(OP)
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.

RE: can you call an array with a variable name

(OP)
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?

RE: can you call an array with a variable name

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

RE: can you call an array with a variable name

(OP)
That's beautiful.Thanks It worked perfectly.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login



News


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close