none
Proper way to use resources

    Question

  • Hi all,

    I'm using VB.Net 2008 .NET 3.0.

    I am not sure of the proper, or best, way to use Settings and Resources. For now I use the default project wide My.Settings and My.Resources. I have a class that I would like to reuse in other projects, so adding project wide settings or resources in each project doesn't sound proper, nor does creating constants and variables within the class itself.

    I'm guessing there is a way to give a class its own resource file, and maybe even settings file, but I'm not sure how to do it. I tried adding a resource file with the same name (but with .resx extension) and I got a weird error saying I was trying to edit a resource that is apart of another project. I continued, but it didn't seem to be what I wanted and I wasn't sure how to access that new resource.

    I'm not currently concerned with internationalization, but it wouldn't hurt to understand how that would affect what I'm trying to do.

    Can you please help me with some advice as to the proper technique?

    Thank you,

    Miarez
    Tuesday, June 08, 2010 9:03 PM

Answers

  • Hi Miarez,

    You can Use A Class library:

    And write your code and resources and settings but don't forget to "public" before the classes that you will share with another application.

    After that go to your project and click Project menu >> Add reference ... and then chose browse tab and select you DLL library that you made.

    and don't forget to write "Imports Yourlibraryname" before "Public class Form1"

    ---------------

    don't forget to mark this post as answer if this post help you

    ---

    Mohamed Elghamry


    Try my new web explorer
    Genius Web Explorer
    Go to the Home Page
    • Marked as answer by Miarez Wednesday, June 09, 2010 5:44 PM
    Wednesday, June 09, 2010 5:38 PM

All replies

  • I am not sure I understand your question.  Are you trying to share resources and settings between multiple projects/applications?
    Herfried K. Wagner [MVP]
    Tuesday, June 08, 2010 11:38 PM
  • Your resources will be embeded in your assembly, your settings will stay in the program.exe.config at run time and can be changed at any time (even by the enduser)

     However, for most of those things, it cost less time to create a simple program to try it, there is no magic in VB.


    Success
    Cor
    Wednesday, June 09, 2010 6:00 AM
  • No.  Maybe I'm approaching this all wrong.  I have a class that I would like to re-use.  Within that class I have things like hard coded strings, numbers, etc.  As I understand it, those should not be hard coded, but should instead be put into a resource file.  The alternative seems to be to add a bunch of constants or enums, which also doesn't seem to be the correct way to do it.

     

    Let me ask this, where do you put things like custom exception strings, default values, and "magic" values in a class that you want to re-use?

    Wednesday, June 09, 2010 3:37 PM
  • I think you are looking for win32 resources where you can create string table inside resources file

    kaymaf


    CODE CONVERTER SITE

    http://www.carlosag.net/Tools/CodeTranslator/.

    http://www.developerfusion.com/tools/convert/csharp-to-vb/.

    Wednesday, June 09, 2010 3:50 PM
  • Hi Miarez,

    You can Use A Class library:

    And write your code and resources and settings but don't forget to "public" before the classes that you will share with another application.

    After that go to your project and click Project menu >> Add reference ... and then chose browse tab and select you DLL library that you made.

    and don't forget to write "Imports Yourlibraryname" before "Public class Form1"

    ---------------

    don't forget to mark this post as answer if this post help you

    ---

    Mohamed Elghamry


    Try my new web explorer
    Genius Web Explorer
    Go to the Home Page
    • Marked as answer by Miarez Wednesday, June 09, 2010 5:44 PM
    Wednesday, June 09, 2010 5:38 PM
  • Miarez,

    if it are constants then the best thing you can do is make them hard-coded.

    The use of enums of that is a very good way to keep your program like it should be; easy to maintain.

    Which does not mean that the constants have to be in one class, you can simply make an extra class for that, with nice properties which gets the constant values.

    VB Net is not a kind of amateur scripting tool.


    Success
    Cor
    Wednesday, June 09, 2010 5:42 PM