Results 1 to 8 of 8

Thread: load a resources file

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Posts
    224

    load a resources file

    Hi,

    How can I load a resources file like a picture with a variable?

    Example that not work:
    VB Code:
    1. Me.PictureBox1.Image = My.Resources.MyVariable

  2. #2
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    372

    Re: load a resources file

    use LoadResPicture ( rsrcIndex, 0)
    where rsrcIndex is the name of the pic in your resource file

  3. #3
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    372

    Re: load a resources file

    use LoadResPicture ( rsrcIndex, 0)
    where rsrcIndex is the name of the pic in your resource file

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: load a resources file

    How have you created this resource in the first place? Are you using VB 2005 (please, please, please specify in future)? Have you added the image via the Resources tab of the project properties? Did you add it as an Image resource? If the last three answers were Yes then the code you provided will work, which suggests that that is not what you did.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Posts
    224

    Re: load a resources file

    Hi,

    I am using Microsoft Visual Basic 2005 Express Edition.

    Yes, the three answers are yes.

    I have five pictures in my resources tab:

    _01 _02 _03 _04 _05

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: load a resources file

    I would strongly suggest that you use descriptive names for everything. Giving anything a name like _01 is never an asset. If you've add an Image resource named _01 to your project via the resources tab then to display it in a PictureBox you would use:
    VB Code:
    1. myPictureBox.Image = My.Resources._01
    That's exactly what I used in the attached screenshot and you can see the image displayed. You said that that code you posted earlier didn't work. What does that mean? Did the code execute but you didn't see the image? Did your app throw an exception? Did your computer explode?
    Attached Images Attached Images  
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Posts
    224

    Re: load a resources file

    Hi,

    This what I am try to do:

    NumPicture = NumPicture + 1
    MyVariable = Format(NumPic, "00")
    Me.PictureBox1.Image = My.Resources.MyVariable

    I get this error:
    MyVariable is not a member of Resources

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: load a resources file

    You simply cannot do stuff like that. Do a search on the forum for "reflection" and see how many times it's been posted that a string is not an identifier and an identifier is not a string and if you want to use a string to refer to a type member then you have to use reflection. If you want to use numbers to identify things then put the objects in an array or a collection and use the number as an index.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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