Loading string resource from a file

D

dev15

Hi, i am developing a vb localised app for Pocketpc 03 and WM5.
I have resource files for German and English called Resources.de.resx
and Resources.resx

I am trying to create a resource manager object :
LocalApp is my app namespace, However the code does not compile
due to the rm = New ResourceManager("LocalApp.Resources", Assembly.GetExecutingAssembly()))
statement. I also tried using My.Resources but that doesn't pass the Intellisense checker.

I noticed my resources files are in a My Project folder which the wizard generated, don't know
if this is causing an issue.

What is is the best way to access the resources in the satellite assemblies.




Public Shared Sub Main()

rm = New ResourceManager("LocalApp.Resources", Assembly.GetExecutingAssembly()))

objFrmMain = New Form1

Application.Run(objFrmMain)

End Sub
 
G

Guest

The best way if using VS 2005 is to move the Resources.resx file (any any
other language resources) to the Properties folder under your project. VS
will then create a wrapper class which enables you to access the resources
via strongly typed properties.

ie for a string resource:
string myErrorMessage =
Properties.Resources.FailedToInstallCabReturnCodeNotZero

This also works for icons, images etc...

So using this method you need not work directly with the ResourceManager
class.
 
D

dev15

Sorry for the ignorance, but i don't have a 'Properties' folder under my app
directory. Do i need to create one?

Currently the .resx files and assembly.vb is under a My Project folder which
the wizard created under my app directory. The other folders under the app
directory are 'bin' and 'obj' of course
 
G

Guest

With VS2005 you shouldn't have to work directly with the ResourceManager
class. I could tell you how, but you haven't have to so I'll help you get the
new feature in VS 2005 working.

I don't have VB installed as I don't use it but if you right click your
project, then click the Resource tab, this should enable you to add strings,
images etc. Again, nit sure how this works for localized resources, but doing
this should add a default resx file to your project.

To access the strongly typed class as a result from the above, I believe in
VB you need to use the My.Resources object.

See here for more info:
http://msdn2.microsoft.com/en-us/library/dhs35kds(VS.80).aspx

My.Resources is covered here:
http://msdn2.microsoft.com/en-us/library/6wkcc526(VS.80).aspx
 
D

dev15

The intellisense does not recognise My. in my project do i need
to import anything library or something.
 
D

dev15

Thanks for the reply, i'm using VS2005 and VB.NET Compact Framework
Version 1 Service Pack3. Is the My object available in CF 1 SP3?

I've created a very basic PocketPC app with 1 form with a label on. I've
have
a resource file with a single string in.

Me.Label1.Text = My.Resources.Welcome

The intellisense doesn't recognise My.
 
G

Guest

The version of CF is irrelevant, it is the version of Studio that implements
this functionality.

have you tried adding a resource via the properties screen?
 
D

dev15

Thanks, i added a resource by right clicking on the project in the solution
then Add item then chose resource.

If i go to the Right click on project in Solution explorer then project
properties screen
i only have the following tabs:

Application
Compile
Debug
References
Signing
Devices

How can i add a resource from this screen?
 
G

Guest

None of the "My" namespace exists in the Compact Framework - largely because
it doesn't provide anything that can't be gotten through other calls.

Studio 05 projects can create a resource file directly for a project (in
project properties) or you can add them manually. It will then generate a
typesafe wrapper for each string in the file (unless you turn off the
external tool that does it).

If you use the typesafe wrapper, you don't need to use the ResourceManager.
If you find that the wrapper doesn't meet your needs (which certainly can be
the case) then you use something like this (namespaces and assembly manes
will likely be different for you):

This assumes all string resources are in a separate assembly called
Customer.Globalization.dll

Assembly asm = Assembly.Load("MyCustomer.Globalization");
m_rm = new ResourceManager("MyCustomer.Globalization.Strings", asm);
.....
public static string GetString(string name, CutureInfo culture)
{
return m_rm.GetString(name, culture);
}



--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Managed Code in an Embedded World
www.OpenNETCF.com
 
G

Guest

If the project has no resources, you should get a "designer" page that says
"This project does not contain a default resources file. Click here to
create one." Clikc that link.

If the resource file already exists, you will get a resource grid for
entering the resource strings.

There are a couple excellent books in print of Globalization with .NET
applications. If you're going to do much of this, picking one up might not
be a bad idea.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Managed Code in an Embedded World
www.OpenNETCF.com
 
G

Guest

Sorry, it seems this feature is not available when targeting CF1 in a VS2005
project.

I thought you'd already had your resource files added to your project, you
said you had two resource files. Now that you have added one, ensure the
generic resource name is Resource.resx, can you now use My.Resources within
the VS editor?
 
D

dev15

Thanks Chris, i got it working use VB version of your code below.
But how do i use the TypeSafe wrapper where is this?
 
G

Guest

I am assuming that if you cannot use the My.Resources in VB under 2005 then
it is not supported.

However, I am no where near 100% on this as I am not a VB programmer. In C#,
this functionality is available compiling against CF1 in 2005 under C# you
have the Properties.Resources syntax - but the same overall result which
probebly leads to the same IL.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top