Object reference through String

Microsoft Visual studio 2008 professiona...
April 20, 2010 at 14:35:45
Specs: Windows 7
I have a string that contains an object name, and want to use that string to reference that object that it contains. Is there a way to do this. For example if you have an multiple objects and one of them is davidimagelist and another is joelimagelist. Then you have a string that contains "joelimagelist". Is there a way you can use the string to be as the object to which is equal to what it contains.

See More: Object reference through String

Report •

#1
April 20, 2010 at 19:54:02
well, this worked, as a test:
test="scripting.filesystemobject"
set fso=(test)
'---- end
i would imagine other objects equally transferable, via the "set" instruction.

Report •

#2
April 21, 2010 at 03:47:39
I am looking for a way to do this in vb.net. The logic that you have given may help me out though. I am not sure the language you are using (looks like C#). If you know how to do this in the Visual Basic language please let me know.

Report •

#3
April 21, 2010 at 08:22:52
I'm wondering why you'd want to do so in the first place. There's probably a better way to go about doing whatever it is you're attempting.

Report •

Related Solutions

#4
April 21, 2010 at 08:26:05
i tested that in visual basic 3.2, but i know there's lots of differences between .net and older veebees. the "scripting.filesystemobject" was just a convenient object for me to use. i works equally well with, f/e: "excel.application".

Report •

#5
April 21, 2010 at 09:36:59
Still have not been able to do it. The reason for doing so is that I have a program that I want to be able to add information quickly without having to add more code. I have a imagelist that contains different pictures of characthers with each picture filename named as the name. This name is then set as a string with the extention trimmed off. Then I am trying to use the name to correspond with another imagelist having the imagelist name being the same as the string. Right now I have gotten the program to work but I have to add the character in code when I add new characters. If I can get the value of the string varable to reference the imagelist that has the same name as the string contained in the variable this would make adding characters easy without adding more code.

Report •

Ask Question