Results 1 to 4 of 4

Thread: [RESOLVED] possible to check if image exists in dir when i call load event in picturebox

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,586

    Resolved [RESOLVED] possible to check if image exists in dir when i call load event in picturebox

    based tis code, how to check if image ND.jpg, exists in dir, if not exists clear the picturebox:

    Code:
    ...
    Me.PICOM.Cls
            Set PICOM.Picture = Nothing
            MYFOLDER = "C:\Lavori_Vb6\TEST_MAPPA\IMG\ND.jpg"
            Me.PICOM.Picture = LoadPicture(MYFOLDER)
            Me.PICOM.Picture = Me.PICOM.Image
    ...

  2. #2
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,176

    Re: possible to check if image exists in dir when i call load event in picturebox

    poorly written post

    Are you saying that if ND.jpg is not in your folder ("C:\Lavori_Vb6\TEST_MAPPA\IMG"), then clear the picturebox?

    Sam I am (as well as Confused at times).

  3. #3
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,176

    Re: possible to check if image exists in dir when i call load event in picturebox

    Something like this?

    Code:
    Option Explicit
    Private Sub Command1_Click()
        FileExists ("C:\Lavori_Vb6\TEST_MAPPA\IMG.ND.jpg")
    End Sub
    
    Private Function FileExists(ByVal sFileName As String) As Boolean
        Dim intReturn As Integer
        On Error GoTo FileExists_Error
        intReturn = GetAttr(sFileName)
        FileExists = True
        'EDIT:
       'You might want to add this if the file DOES exist:
       'PiCom.Picture = LoadPicture("C:\Lavori_Vb6\TEST_MAPPA\IMG.ND.jpg")
    Exit Function
    FileExists_Error:
        FileExists = False
        PiCom.Picture = LoadPicture("")
       'OR, probably better:
       'Set PiCom.Picture = Nothing
    End Function
    Last edited by SamOscarBrown; Dec 3rd, 2022 at 12:10 PM.
    Sam I am (as well as Confused at times).

  4. #4
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,176

    Re: possible to check if image exists in dir when i call load event in picturebox

    Or, simpler to understand with IF-Statement:

    Code:
    Option Explicit
    
    
    Private Sub Command1_Click()
        If FileExists("C:\Lavori_Vb6\TEST_MAPPA\IMG.ND.jpg") Then
            PiCom.Picture = LoadPicture("C:\Lavori_Vb6\TEST_MAPPA\IMG.ND.jpg")
        Else
            Set PiCom.Picture = Nothing
        End If
    End Sub
    
    
    Private Function FileExists(ByVal sFileName As String) As Boolean
        Dim intReturn As Integer
        On Error GoTo FileExists_Error
        intReturn = GetAttr(sFileName)
        FileExists = True
    Exit Function
    FileExists_Error:
        FileExists = False
    End Function
    Sam I am (as well as Confused at times).

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