Results 1 to 10 of 10

Thread: [RESOLVED] Image Viewer Unable to load Image

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2009
    Posts
    64

    Resolved [RESOLVED] Image Viewer Unable to load Image

    Hi guys,

    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.

    Thanks
    Attached Files Attached Files

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Image Viewer Unable to load Image

    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

  3. #3
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,170

    Re: Image Viewer Unable to load Image

    whats wrong with that? it works fine for me.
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


  4. #4

    Thread Starter
    Lively Member
    Join Date
    Aug 2009
    Posts
    64

    Re: Image Viewer Unable to load Image

    Quote Originally Posted by westconn1 View Post
    as far as i can see the listimage box does not contain the path with the file name
    So how do I resolved it? Using
    Code:
    LoadImage App.Path & "\" & lstImages.List(lstImages.ListIndex)
    Also dont work it returns the same error.

    @ 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.

  5. #5
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,170

    Re: Image Viewer Unable to load Image

    @clippitch, the above shown code was disabled in ur attached file.
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


  6. #6
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,170

    Re: Image Viewer Unable to load Image

    i tried that disabled code in a seperate button it works fine.
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


  7. #7

    Thread Starter
    Lively Member
    Join Date
    Aug 2009
    Posts
    64

    Re: Image Viewer Unable to load Image

    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.

  8. #8
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,170

    Re: Image Viewer Unable to load Image

    thats also working here with the code u posted.
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


  9. #9

    Thread Starter
    Lively Member
    Join Date
    Aug 2009
    Posts
    64

    Re: Image Viewer Unable to load Image

    Got It working Thanks so much guys
    This is the code.
    Code:
    Private Sub lstImages_Click()
           LoadImage txtDir.Value & "\" & lstImages.List(lstImages.ListIndex)
    End Sub

  10. #10
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: [RESOLVED] Image Viewer Unable to load Image

    ha! i had it right
    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

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