Results 1 to 3 of 3

Thread: PictureBox loading a picture selected in a FileListBox

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2009
    Posts
    4

    PictureBox loading a picture selected in a FileListBox

    Hello, I have been stuck on this for a while so I thought I would ask you guys for help. I have been trying to get a PictureBox to load an image I choose in a FileListBox. Here is the code I have so far, and the error:

    Code:
    Private Sub File1_Click()
    FileName = File1.Path
    If Right$(FileName, 1) <> "\" Then FileName = FileName & "\"
    FileName = FileName & File1.FileName
    Main.Show
    Main.Image.Picture = LoadPicture(File1.Path + File1.FileName)
    Me.Hide
    End Sub
    The error I get is:

    Runtime error 53
    File not found: 'e:\H\Picimage.jpg'

    Now I know what is wrong here. The proper directory is e:\H\Pic\image.jpg
    I tried to change line six of my code to: Main.Image.Picture = LoadPicture(File1.Path + "\" + File1.FileName)

    But now i get runtime error 438:
    Object doesn't support this property or method.

    Any way to make this work?

  2. #2
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: PictureBox loading a picture selected in a FileListBox

    Why have you gone to the trouble of setting 'Filename' and then not used it ?
    Also, for string concatination use '&' rather than "+"
    Code:
    Private Sub File1_Click()
    Dim strFileName As String
    strFileName = File1.Path
    If Right$(strFileName, 1) <> "\" Then strFileName = strFileName & "\"
    strFileName = strFileName & File1.FileName
    Main.Show
    Main.Image.Picture = LoadPicture(strFileName)
    Me.Hide
    End Sub

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: PictureBox loading a picture selected in a FileListBox

    Quote Originally Posted by BadPrenup View Post
    Now I know what is wrong here. The proper directory is e:\H\Pic\image.jpg
    I tried to change line six of my code to: Main.Image.Picture = LoadPicture(File1.Path + "\" + File1.FileName)
    That was the right thing to do, and solved that issue.

    The changes Doogle showed make it a bit better.

    But now i get runtime error 438:
    Object doesn't support this property or method.
    That is referring to this piece of the code:
    Code:
    Main.Image.Picture =
    An Object is an item before a dot (in this case, Main and Image) and a Property/Method is an item after a dot (in this case, Image and Picture).

    The first thing to check is that the item called Main has a sub-item called Image.

    If that isn't the issue, check that the sub-item Image has a property called Picture (the simplest way to do that is to delete and re-type the dot, as you will be shown a list of valid properties).

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