VB.Net and object checking

Permabanned
Joined
24 Dec 2002
Posts
474
Location
Chelmsford, Essex. Bling Bling
Ive got a string variable that holds the name of an object.

What i want to do is check to see if that object exists before creating it

Normally you'd do

If objWhatever is nothing then
objWhatever = new blahblah
endif

what i want to do is use the contents of the string as the object name and do the check on that.

Any hope of doing this in VB.net?
 
Erm, that's a dodgy area to be honest. It might be possible using reflection, although I'm not certain as I've never used it.

Why do you need to refer to objects by their name as a string in the first place? Why not just use a generic Dictionary<> collection? (Or its equivelant VB.NET syntax... I'm a C# man.)
 
Last edited:
You can do this via reflection if you know the assembly name and the class name.

Like Inquisistor says I'm concerned that you would want to though.
If there is no other way around this, i.e. you have the class name stored in a config file as a string maybe, then have a look through MSDN for the System.Reflection namespace.
 
Back
Top Bottom