Results 1 to 5 of 5

Thread: [Resolved] Weird Resource File Error

Hybrid View

  1. #1

    Thread Starter
    Hyperactive Member neef's Avatar
    Join Date
    Dec 2001
    Location
    Boston
    Posts
    311

    [Resolved] Weird Resource File Error

    Some of the images I have in my resource file can't be used programmatically. By that I mean I get an error with this simple line of code where pbField is a picture box and TFFieldTurf is a jpeg file:

    pbField.BackgroundImage = My.Resources.TFFieldTurf

    The error I receive is:

    Error 8 'TFFieldTurf1' is a type in 'Resources' and cannot be used as an expression.

    How can an actual file be considered a type not an object? Some of my other pics get the same error, but others work just fine. It has nothing to do whether they are jpegs, pngs, or tifs either. If I use the designer to set the background property I get no errors. Only when I write my own code.

    What am I missing here?

    Thanks in advance.
    Last edited by neef; Feb 26th, 2018 at 07:59 PM.
    Intermediate Level Programmer Extraordinaire

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Weird Resource File Error

    If it's a resource then it's not a file to begin with. The whole point of resources is that they are data compiled into your EXE rather than separate files. The way My.Resources generally works is that it provides read-only properties that internally extract the embedded data and create an object from it of the appropriate type.

    I've never encountered a situation like yours but then I've only ever embedded a small number of file types. The type of object created depends on the type of file embedded so maybe the type of file you embedded requires the generation of a dedicated type and a separate property to return an instance of that type. What type of file did you start with?

    Also, have you actually looked at the relevant code? If you click Show All Files in the Solution Explorer and expand the My Project node then you can access the code file in which the contents of the My.Resources namespace is generated, so you can see exactly what types and member are available.

  3. #3

    Thread Starter
    Hyperactive Member neef's Avatar
    Join Date
    Dec 2001
    Location
    Boston
    Posts
    311

    Re: Weird Resource File Error

    Thanks for your response, jm.

    I took a look at code file for my resources like you said. Never saw that before, thanks! Through that file I did some exploring and located how the designer accessed the same bitmap file I was trying to access. So instead of:

    My.Resources.TFFieldTurf

    I found:

    My.Resources.Resources.TFFieldTurf1

    Now it works! There was another "level" of Resources. Is this some directory problem I have inadvertently created? Did I load the image to an incorrect path?
    Intermediate Level Programmer Extraordinaire

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

    Re: Weird Resource File Error

    The "other level" you're talking about is a module and it's standard. Each resource must be accessed via a property, so there must be something that those properties are members of. Remember that members of modules can be referred to in VB without qualifying them with the type name, unlike Shared members of classes. There is a My.Resources namespace and a Resources module declared as a member of that namespace. As such, My.Resources.SomeResource and My.Resources.Resources.SomeResource are actually the same property. The second one simply fully qualifies it with the module name while the first one omits the module name.

    I'm still interested to know what type of file you added in the first place, because I've never seen a new type defined in My.Resources before. I have embedded files that have produced resource properties of type String, Image or Byte(). Your file type seems to have required something else, so that TFFieldTurf type was generated. That TFFieldTurf1 property would then return an instance of that type. The "1" suffix was required because, due to the fact that module names can be omitted, there would have been no way to know whether My.Resources.TFFieldTurf was referring to the type or was omitting the module name and referring to the property.

  5. #5

    Thread Starter
    Hyperactive Member neef's Avatar
    Join Date
    Dec 2001
    Location
    Boston
    Posts
    311

    Re: Weird Resource File Error

    The original file type I embedded was a .jpg pic. When I cut and pasted the code into this thread I was careless. There was a "1" at the end of the line:

    My.Resources.TFFieldTurf

    so it red:
    My.Resources.TFFieldTurf1

    TFFieldTurf1 was the actual name of the .jpeg because I made a lesser version and then improved it. I must have been in a rush when i copied the code and the "1" was lopped off. Not sure this is helpful, but this thread has been to me, so thank you again.
    Intermediate Level Programmer Extraordinaire

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