Help needed with picture box problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Flinty
    New Member
    • Jan 2013
    • 11

    Help needed with picture box problem

    I am trying to pass a variable containing the name of an image into the loadpicture method of a picture box. As I wish to do this with various different images I cannot enter the literal name of the image. So far I have been unable to do this, so help is needed.

    Flinty
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    It would help to see the code.

    Comment

    • Flinty
      New Member
      • Jan 2013
      • 11

      #3
      Code:
      Private Sub lstTrophy_Click()
      Dim FilName
          lstWinners.Clear 
          txtHistory.Text = ""
          Aname = Trim(lstTrophy.Text) 
          FilName = "C:\TrophyPics\Aname"
      'Show picture of trophy.
      pic1.Picture = LoadPicture(FilName)
      
      End Sub
      Run time Error 53
      File not found
      Last edited by Rabbit; Jan 28 '13, 06:37 AM. Reason: Forgot the error number. Fixed code tags.

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        Your FilName variable contains no picture file.

        Comment

        • Flinty
          New Member
          • Jan 2013
          • 11

          #5
          Sorry, I did not explain that AName is a global variable and holds the image name contained in the listbox.text value. Then FilName is the complete path of the directory and the image name. I have tried various combinations of variables and just using the listbox.text value, all to no avail.

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            Like I said in my first post. Your FilName variable doesn't contain the image name. You say it contains the image name. But it doesn't. At least not in the code you're showing me. If you're showing me code that is different from what you're using, there's no way for me to help you.

            Comment

            • Flinty
              New Member
              • Jan 2013
              • 11

              #7
              Rabbit,
              I am sorry if you cannot follow my code. The names of the images are held in a listbox(lstTrop hy). The images themselves are located in a folder named TrophyPics in the root C directory. When the user clicks on a name in the listbox, the image of that name is meant to show in the picturebox(pic1 ). That's about as simple as I can make it. Thanks for your continued attention.
              P.S. I am aware it's a bit clunky and I may modify it to use a different method of storing images.

              Comment

              • Rabbit
                Recognized Expert MVP
                • Jan 2007
                • 12517

                #8
                I have no trouble following your code. The problem is that your explanation of the code does not follow your code. You say the FilName has the image name in it.

                Here is your code
                Code:
                FilName = "C:\TrophyPics\Aname"
                It clearly does not contain an image name. If you are attempting to append the value of your Aname variable, that is not how you do it. Variables do not auto expand in strings. If you want to concatenate the value of the variable, you need to do this:
                Code:
                FilName = "C:\TrophyPics\" & Aname

                Comment

                • Flinty
                  New Member
                  • Jan 2013
                  • 11

                  #9
                  Rabbit,
                  Thank you for that. A simple & operator was all it took. Lesson learned as I wasn't aware it was needed!

                  Comment

                  Working...