I am creating an Image viewer using some codes I got from the net. Originally you can only browse an Image per file and load it in the picture box, so what I did is create a listbox and modify the browse button to select a folder instead of per file and load the items in the list box. My problem is when I click items on the listbox it throws an error that its unable to load the image.
The problem reside here:
Code:
Sub LoadImage(Name As String)
If Dir(Name) <> "" Then
With Image1
.AutoSize = True
.Picture = LoadPicture(Name)
m_sngHeight = .Height
m_sngWidth = .Width
.AutoSize = False
.PictureSizeMode = fmPictureSizeModeStretch
m_sngZoom = 1
.Left = 1
.Top = 1
End With
SetZoom m_sngZoom
Else
MsgBox "Unable to load image " & Chr(10) & Name, vbExclamation
End If
End Sub
Upon loading it returns null thats why it goes directly to MsgBox. The code i used in listbox_click even is
Code:
Private Sub lstImages_Click()
LoadImage lstImages.Value
End Sub
Hope someone code shed a light on this one. exp those who are experienced programming in vb.
as far as i can see the listimage box does not contain the path with the file name
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case. Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
@ seenu_1st
The first time I used it it does work, for unknown reason after trying it again the other day it doest work anymore.
If you add another command button and put this code:
Code:
Dim vntFile
Dim strFilters As String
strFilters = "All Image files,*.bmp;*.gif;*.jpg;*.jpeg,Bitmap (*.bmp),*.bmp"
vntFile = Application.GetOpenFilename(strFilters)
If vntFile <> "" Then
TextBox1.Text = vntFile
LoadImage TextBox1.Text
End If
Then browse the folder again, and try clicking on the listbox, it will now load the item. I dont know why.
Yes that's exactly Im pointing out it works fine and image load on the listbox after loading a single image using the code above. But what I want to do is just select the folder list all the images in the folder in the listbox and load the image click in the listbox in the picture box.
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case. Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete