Resolved Is it a common way to add strings to the existing resx file.

aaaron123@roadrunner.com

Well-known member
Joined
Jan 23, 2011
Messages
112
Programming Experience
10+
I'm looking at various ways to add a resource.

I see that a form has a .resx file that I can easily edit in the IDE to include a new string.

It will then automatically be compile into a binary .Resources file.

Nice!

But since the system seems to be using the file for it's own purposes I wonder if that is a good idea.

If the only resource needed is one string is it common to add it to the existing resx file.
 
Solution
As suggested, don't touch a form's RESX file. It is for the form specifically and will be generated and modified by the system based on what you do in the designer. If you make changes to it directly and then make a change in the designer, there's every chance that your manual change will be lost.

If you want to add an application resource then, generally speaking, you should do so using the Resources page of the project properties. Open the project properties, select the Resources page and then click to generate a resource file if required. You'll then get a resource table and you can add a string directly or you can select a file to add. Once you have your resource listed, you can use My.Resources.MyStringResource in code like...

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,557
Location
Norway
Programming Experience
10+
I don't think you should edit the form resx directly, it is generated based on what you do in visual designer. VS also warns about this:
1611757281508.png


If you need to add a resource of your own add it to the application resources (project properties, Resources page).
 

aaaron123@roadrunner.com

Well-known member
Joined
Jan 23, 2011
Messages
112
Programming Experience
10+
I did see that warning when I was checking it out.

I just want to be absolutely sure:
When you say "directly" I believe you are including being in the IDE and adding a string.

I believe when I was playing around I opened the tab you suggested and it said something like it could not find a file - I'll check now.

EDIT
Yep, this is what I see:

An error occurred trying to load the page.
Could not find the file 'C:\Users\aaaron\Visual Studio\Projects\Suite Net5\SuiteMain\My Project\Resources.resx'.

I look in the My Project folder and it is empty.
 
Last edited:

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,557
Location
Norway
Programming Experience
10+
When I say "don't edit directly" I mean "don't touch it" ;)

When I open that page for a new .Net 5 project I see this:
1611759167117.png

When I do the default resource file is created.
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,570
Location
Sydney, Australia
Programming Experience
10+
As suggested, don't touch a form's RESX file. It is for the form specifically and will be generated and modified by the system based on what you do in the designer. If you make changes to it directly and then make a change in the designer, there's every chance that your manual change will be lost.

If you want to add an application resource then, generally speaking, you should do so using the Resources page of the project properties. Open the project properties, select the Resources page and then click to generate a resource file if required. You'll then get a resource table and you can add a string directly or you can select a file to add. Once you have your resource listed, you can use My.Resources.MyStringResource in code like any other String reference, where the property name will be match the resource name you provided or the name of the file you loaded.
 
Solution
Top Bottom