Results 1 to 11 of 11

Thread: Using resources (resx) in VB.NET

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Location
    Mexico City
    Posts
    242

    Unhappy Using resources (resx) in VB.NET

    Hi,

    I've been trying to use resources in VB.NET for the past 4 hours without any luck...

    I added a resource file to my project, called iConvert.resx, then I added a string to it:

    name: test, value: eureka!, comment: (null), type: String, mimetype: (null)

    Then, using this code:

    VB Code:
    1. Module MMain
    2.     Public gresMan As Resources.ResourceManager = New Resources.ResourceManager("iConvert", System.Reflection.Assembly.GetAssembly(GetType(MMain)))
    3.  
    4.     Sub Main()
    5.         MessageBox.Show(gresMan.GetString("test"))
    6.     End Sub
    7. End Module
    I get an error telling me to make sure I linked/compiled iConvert.resources...

    Help me please!
    Live your own life, for you will die your own death.

  2. #2
    Addicted Member wolfofthenorth's Avatar
    Join Date
    Jan 2001
    Location
    Tatooine
    Posts
    169
    I know your pain. For me it took two days to get my resource to work.

    Try using this line

    Me.GetType.Assembly.GetExecutingAssembly()

    instead of this line.

    System.Reflection.Assembly.GetAssembly(GetType(MMain))

    Hope it works for you.
    That which does not kill us, only makes us stronger.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Location
    Mexico City
    Posts
    242
    thanks for replying, but unfortunately, the Me keyword is not valid inside modules

    any other ideas?
    Live your own life, for you will die your own death.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Location
    Mexico City
    Posts
    242
    I also tried:

    gfrmConvert.GetType.Assembly.GetExecutingAssembly

    with the same result...

    gfrmConvert is an instance of the main form.

    If I use this:

    Resources.ResourceManager(GetType(FMain))

    I get no error, but it does not retrieve the string when using GetString...
    Live your own life, for you will die your own death.

  5. #5
    Addicted Member wolfofthenorth's Avatar
    Join Date
    Jan 2001
    Location
    Tatooine
    Posts
    169
    Hi,

    I'm not positive that the line in question is your problem, but it was in my case.

    How about this line?

    System.Reflection.Assembly.GetExecutingAssembly
    That which does not kill us, only makes us stronger.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Location
    Mexico City
    Posts
    242
    hey, could you give me an example of your working code? I can't make mine work
    Live your own life, for you will die your own death.

  7. #7
    Addicted Member wolfofthenorth's Avatar
    Join Date
    Jan 2001
    Location
    Tatooine
    Posts
    169
    Dim RM As New ResourceManager("MyApp.MyResStrings", System.Reflection.Assembly.GetExecutingAssembly())

    MsgBox(RM.GetString("MyString"))

    Hope this helps.
    That which does not kill us, only makes us stronger.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Location
    Mexico City
    Posts
    242
    well, it would be awesome if you could put all the code (the whole solution, zipped) related, because I don't think that the constructor is what is causing the problem... or if anyone can point me to a full example, I'll be very grateful

    thanks for your help so far!
    Live your own life, for you will die your own death.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Location
    Mexico City
    Posts
    242
    oh yeah, life is gooood. I finally got it. You have to use the application name PLUS the resource file name as the baseName on the ResourceManager constructor. I was naming the resource file the same as the app, so it was rather hard to figure this one out...
    Live your own life, for you will die your own death.

  10. #10
    Frenzied Member dinosaur_uk's Avatar
    Join Date
    Sep 2004
    Location
    Jurassic Park
    Posts
    1,098

    Re: Using resources (resx) in VB.NET

    Right...i am absolutely confused by resource manager...

    how do you create one ?

    I need to put all my images into one .resx file...

    how?????

    grrr

  11. #11
    Addicted Member GSIV's Avatar
    Join Date
    Jun 2002
    Location
    Texas, USA
    Posts
    213

    Re: Using resources (resx) in VB.NET

    Wow, this is a very old thread, but perhaps this will help someone using VB.NET 2005.

    Right-click 'Project Properties' in the Solution Explorer
    Select ADD, then NEW ITEM
    Select 'Resources File'
    Choose 'Add Resources' and select the images you want to embed (Image1.jpg)

    In your application, add a PictureBox (PictureBox1)

    In your code, add the following in the proper context with what you are doing:

    PictureBox1.Image = My.Resources.Images.Image1

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width