Convert String to an Object Reference

XL Jedi

Active member
Joined
Apr 2, 2007
Messages
44
Location
Florida
Programming Experience
10+
What's the best way to convert a string to an object reference?

For instance, if I have 3 string variables defined as:
Dim MyString1 as String = ""
Dim MyString2 as String = ""
Dim MyString3 as String = ""

...and then I have a config text file that I read when the application starts that is in the format: VarName, String

MyString1, "mytext1"
MyString2, "mytext2"
MyString3, "mytext3"

How do I do something like:
Object("MyString1").Value = "mytext1"
 
What you're asking for is done via reflection, which is a relatively advanced topic and is rarely needed, even by experienced programmers. There is almost certainly a better way to accomplish what you want and if you'd care to explain the situation more fully we could probably work out what that might be.
 
What you're asking for is done via reflection, which is a relatively advanced topic and is rarely needed, even by experienced programmers. There is almost certainly a better way to accomplish what you want and if you'd care to explain the situation more fully we could probably work out what that might be.

Well... Over a month ago I had asked about how best to go about creating a foreign language config file... heard nothing.

Language Config File

I need to have a foreign language config file so I can send my app to anywhere in the world and have folks be able to easily modify a text config file to suit their language. I don't want to create something hardcoded, where a user would only be able to pick from 2 or 3 supported languages. I need it to be easily editable by the community.

Upon startup the application scans the config file and loads all the language display variables. I'm still open to ideas, what would you suggest?
 
.NET already has a mechanism for that built-in. You design your app to load label text, etc., from a resource file. You then create a resource file for each language you want to support. The Framework will automatically detect the current regional settings of the system and load the appropriate resource file. In order to support new languages you, or someone else, simply has to create a resource file for that language.

Go to MSDN and read about globalization and localization.
 
I already looked at that. I didn't think it was the functionality that I wanted.

As I mentioned, I don't want to create the resource files and support a finite list of languages. I want to allow my users to edit a config file with any simple text editor.

Can the users create and/or edit these resource files easily with a text editor? ...or maybe I can programmatically convert a text config file to one of these resource file formats?

I now believe I can solve the problem with Eval, but I thought I might be able to come up with something more efficient.
 
You could create your own localisation routines. You would need 2 static tables: a list of langauges and a list of display strings. A third table containing a reference to these 2 static tables and the actual display value would also be needed. You could include an editing \ creation screen allowing users to add any language they required. You will also need to record the language preference against each of your users. An advantage behind this method is that it also copes with language specific settings (ie date format etc) and does not require much imagination to make it hold user settings (ie screen colour etc).
There are better ways to do all of this within VB but this is a simple way of adding all of this using a single set of methods.
 
Back
Top