Easy "as object" question

S

shawncraig

I'm sure I'm just missing something here but is there a way to nest
objects inside an object or a collection that functions like an object
with properties BESIDES creating whole classes or making public
variables?

Private Sub Click()
Dim x as SomeSortOfCollection
msg box(x.Name & " " & x.Phone)
End Sub

Private Function Person() as SomeSortOfCollection
Dim Name as String= "John"
Dim Phone as String = "888-888-8888"
Person.Add(Name)
Person.Add(Phone)
End Function


What I'm not looking for:
Anything using a for each method
Using a key value like SomeObject("Name").value
 
G

Guest

What I'm not looking for:
Anything using a for each method
Using a key value like SomeObject("Name").value

It's called a Dictionary/Hashtable :)

Take a look at the System.Collections Namespace.
 
M

Mr. Arnold

I'm sure I'm just missing something here but is there a way to nest
objects inside an object or a collection that functions like an object
with properties BESIDES creating whole classes or making public
variables?

Private Sub Click()
Dim x as SomeSortOfCollection
msg box(x.Name & " " & x.Phone)
End Sub

Private Function Person() as SomeSortOfCollection
Dim Name as String= "John"
Dim Phone as String = "888-888-8888"
Person.Add(Name)
Person.Add(Phone)
End Function


What I'm not looking for:
Anything using a for each method
Using a key value like SomeObject("Name").value


You can use a strong type collection of objects. You can load the collection
with the objects.

You can create a function/method within the collection object to search for
object based on the value looking for and either stop on the object and
address the object or have the object returned from the collection so that
you can address its values.

You can use a for each loop in the function/method within the collection.

The one object call it NamePhone would contain property Let and Get for the
Name and Phone properties, and one NamePhone object is loaded into the
collection for each NamePhone object populated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top