• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 395
  • Last Modified:

assign properties to array elements

What is the best approach for creating my own properties to items in an array?

For example, I will have an array of places.  The Array will be populated by a list created by the user on an excel worksheet.  I would like each place to have properties, such as name, etc., etc.  Some properties will be assigned through the list the user created, others will be assigned from external data (Web Query).  

I'm thinking (after being setup properly) assigning a value to the property would look something like this: place(i).name = "Hell".

Any insight is appreciated, thanks.
0
growedup
Asked:
growedup
2 Solutions
 
Chris BottomleyCommented:
You could declare a type and then assign the type of the variable to that i.e.

type fred
    place as string
    name as string
end type

dim arr(1 to 3) as fred

arr(1).name = "norman"
arr(1).place = "hell"

Chris
0
 
x-menIT super heroCommented:
crate an array within the array
properteis[0] = "hell" ' Name
properteis[1] = .. ' other property
...

Places(i,properties(x))
0
 
x-menIT super heroCommented:
Places(i,properties(x)) is not in the ccoorect syntax
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Michael FowlerSolutions ConsultantCommented:
you could always use a dictionary instead of an array.
Have a look at
http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/A_3391-Using-the-Dictionary-Class-in-VBA.html
for more info on this class
0
 
growedupAuthor Commented:
For this project, declaring a type is the best solution.  Using a dictionary is a great solution as well, but is too complex for this project.  I will definately be considering it for future projects though.
0
 
growedupAuthor Commented:
Thanks for all the fast inputs everyone!
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now