By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,353 Members | 1,237 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,353 IT Pros & Developers. It's quick & easy.

Problem Adding and Using Resource Files

P: n/a
Hey All,

I am building a solution which will have many strings that will need to be
localized (i.e. strings for toolbars, strings for different WinForms,
strings for messages and error messages, etc.).

I am having trouble accessing string file resources.

What I want to do is to break out strings into separate files so that they
are easier to manage and such that I don't have to look through hundreds to
find, edit or delete something.

How can I use code similar to that below:

Dim rm As ResourceManager
Dim Message as StringBuilder

rm = New ResourceManager("StringTable", Me.GetType().Assembly)

Message = New StringBuilder()
Message.Append(rm.GetString("String1"))
Message.Append(rm.GetString("String2"))
MessageBox.Show(Message.ToString())

Right now, when I try the above I get an error claiming that such resources
cannot be found. The text file is listed under the resources. What's
wrong?

Am I missing something in regards to the structure of the text file or
perhaps how it is added?

Please advise.

Thanks,

TC
Nov 8 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Am I missing something in regards to the structure of the text file or
perhaps how it is added?
I assume you're using Visual Studio (?). If so then are you aware that it
already has a built-in mechanism to handle strings for you (with relatively
little work on your part)?
Nov 8 '06 #2

P: n/a
Hey Larry,

As I mentioned in the original post, I am using the stings available under
"Resources".

What I am asking for is a way to segregate these strings into intelligent
collections probably via separate files.

That said, how can I load and use separate resource files into the list of
resources?

How can I use code similar to that below:

Dim rm As ResourceManager
Dim Message as StringBuilder

rm = New ResourceManager("StringTable", Me.GetType().Assembly)

Message = New StringBuilder()
Message.Append(rm.GetString("String1"))
Message.Append(rm.GetString("String2"))
MessageBox.Show(Message.ToString())

Regards,

TC
"Larry Smith" <no_spam@_nospam.comwrote in message
news:ul**************@TK2MSFTNGP02.phx.gbl...
>Am I missing something in regards to the structure of the text file or
perhaps how it is added?

I assume you're using Visual Studio (?). If so then are you aware that it
already has a built-in mechanism to handle strings for you (with
relatively little work on your part)?

Nov 8 '06 #3

P: n/a
Hey Larry,
>
As I mentioned in the original post, I am using the stings available under
"Resources".

What I am asking for is a way to segregate these strings into intelligent
collections probably via separate files.

That said, how can I load and use separate resource files into the list of
resources?

How can I use code similar to that below:

Dim rm As ResourceManager
Dim Message as StringBuilder

rm = New ResourceManager("StringTable", Me.GetType().Assembly)

Message = New StringBuilder()
Message.Append(rm.GetString("String1"))
Message.Append(rm.GetString("String2"))
MessageBox.Show(Message.ToString())
What I was alluding to is that you don't need to do this (or rather you're
probably making your life more difficult). First, ".resx" files for forms
are handled automatically by VS (referring to all strings that appear on
your forms for instance). If you're not aware of the details please let me
know (it seems that way). For other resources like error messages and so
forth, go to Solution Explorer and right-click your project's node. Select
"Properties" from the context menu and click "Resources" on the left-hand
side. A table now appears where you can enter all (non-form) resources which
are usually strings (you may have to click on the notice in the middle of
the window first if there is one - it will be present if it's the first time
doing this). VS then creates a wrapper class called "Resources" where you
can now access any single resource (string or whatever) via the
<YourProjectNamespace>.Properties.Resources.<Resou rceNamestatic property
(a "using <YourProjectNamespace>.Properties" statement is required in each
source file of course). For instance, if you add "MyString=Whatever" to the
table and your project's namespace is "YourProjectNamespace", you can do
this:

using YourProjectNamespace.Properties;
// ...
string MyString = Resources.MyString;

You can access all resources this way, not just strings.
Nov 9 '06 #4

P: n/a
Hey Larry,

Yes, I am already using the catch-all resources file and I'm also using the
resource files exposed to userforms.

My question is, if I want to, how can I break the strings in the catch-all
resource out into separate files?

Regards,

Todd

"Larry Smith" <no_spam@_nospam.comwrote in message
news:uw**************@TK2MSFTNGP04.phx.gbl...
>Hey Larry,

As I mentioned in the original post, I am using the stings available
under "Resources".

What I am asking for is a way to segregate these strings into intelligent
collections probably via separate files.

That said, how can I load and use separate resource files into the list
of resources?

How can I use code similar to that below:

Dim rm As ResourceManager
Dim Message as StringBuilder

rm = New ResourceManager("StringTable", Me.GetType().Assembly)

Message = New StringBuilder()
Message.Append(rm.GetString("String1"))
Message.Append(rm.GetString("String2"))
MessageBox.Show(Message.ToString())

What I was alluding to is that you don't need to do this (or rather you're
probably making your life more difficult). First, ".resx" files for forms
are handled automatically by VS (referring to all strings that appear on
your forms for instance). If you're not aware of the details please let me
know (it seems that way). For other resources like error messages and so
forth, go to Solution Explorer and right-click your project's node. Select
"Properties" from the context menu and click "Resources" on the left-hand
side. A table now appears where you can enter all (non-form) resources
which are usually strings (you may have to click on the notice in the
middle of the window first if there is one - it will be present if it's
the first time doing this). VS then creates a wrapper class called
"Resources" where you can now access any single resource (string or
whatever) via the
<YourProjectNamespace>.Properties.Resources.<Resou rceNamestatic property
(a "using <YourProjectNamespace>.Properties" statement is required in each
source file of course). For instance, if you add "MyString=Whatever" to
the table and your project's namespace is "YourProjectNamespace", you can
do this:

using YourProjectNamespace.Properties;
// ...
string MyString = Resources.MyString;

You can access all resources this way, not just strings.

Nov 9 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.