Results 1 to 2 of 2

Thread: Need to transfer to resources

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2021
    Posts
    41

    Need to transfer to resources

    Hi, my project needs certain images to work properly, so far I am only able to get them to work when in an external folder, I want to move them (the images) to the resources file. This is what I currently have in code.

    Code:
     If k > 0 Then
                                                    Tile.Image = New Bitmap("data/tiles/tile_" & TileState(0, x, k - 1) & ".png")
                                                    TileState(0, x, k) = TileState(0, x, k - 1)
                                                Else
                                                    Tile.Image = New Bitmap("data/tiles/tile_0.png")
                                                    TileState(0, x, k) = 0
                                                End If
    What I have tried is

    Code:
     While My.Resources.ResourceManager.GetObject("_" + CStr(maxn) + ".png") And scnt <= 31
                scnt += 1
                img(scnt) = Image.FromFile("_" + CStr(maxn) + ".png")
                maxn *= 2
            End While
            If maxn <= 2048 Then
                MsgBox("Missing base map _" + CStr(maxn) + ".png", vbOKOnly + vbExclamation, "hint")
                Me.Close()
            End If
    But that doesn't work
    Last edited by Yourmomsfire; Sep 5th, 2021 at 11:50 PM.

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

    Re: Need to transfer to resources

    Firstly, "that doesn't work" is never an acceptable description of a problem. All sorts of things could be the cause of the issue and the specific symptoms you see are the most important diagnostic tool in determining which it is. We should have to trawl through the code and try to work out or guess what might actually be happening. If there's a compilation error then tell us what it is and exactly where it occurs. If there's a run-time exception then tell us exactly what it is, where it occurs and what data was in use at the time. You need to make the effort to help us help you, which means debugging your code if appropriate and providing all the relevant information in your post.

    Regardless, this code makes no sense:
    vb.net Code:
    1. While My.Resources.ResourceManager.GetObject("_" + CStr(maxn) + ".png") And scnt <= 31
    You're obviously trying to get an Image from resources so how can it possibly make sense to AND that with a Boolean expression? You need to provide the name of the resource to GetObject and that probably doesn't include a file extension. You should look - you should already have looked - at the code in each of the properties in My.Resources to see how they are implemented. They will be calling ResourceManager.GetObject and that will show you what an appropriate call looks like. That method will return an Object reference that you can then cast as type Image. If what you're actually trying to achieve there is a check whether GetObject returns Nothing, i.e. there is no resource with that name, then that's what you need to actually do:
    vb.net Code:
    1. Dim img = DirectCast(My.Resources.ResourceManager.GetObject(resourceName), Image)
    2.  
    3. If img IsNot Nothing Then
    4.     'Use img here.
    5. End If

Tags for this Thread

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