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?
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
Re: PictureBox loading a picture selected in a FileListBox
Quote:
Originally Posted by
BadPrenup
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.
Quote:
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).