labisem Posted May 22, 2003 Posted May 22, 2003 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. Quote
*Gurus* divil Posted May 22, 2003 *Gurus* Posted May 22, 2003 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. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.