Auto generate instances (VB)

labisem

Newcomer
Joined
May 20, 2003
Messages
10
Auto generate instances

I have a class, Let's say Public Class Employee, and I want to make an instance of this class (Dim emp1 As New Employee) every time the user wish for it, for example with a button click.
Also, after the creation of the object (instance), how can I have access to the particular object (emp1.Age), if I don't know it's name?

This may be a simle thing, but I don't know how it's done.
 
If you are creating instances on the fly like this you have to store them somewhere before you'll be able to go back and use them again. There are a multitude of collection classes in the framework, take a peek at the System.Collections namespace. ArrayList would probably suit you fine.

With Option Strict on you will have to explicitly cast when you get objects out of the collection, to avoid this you can inherit from CollectionBase and make you own strongly-typed collection, but it's not essential.

Remembed that objects created at runtime don't have names.
 
Back
Top