Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

VB6 - File Searching (Invalid Procedure Call)

  • 10-03-2007 7:36pm
    #1
    Registered Users, Registered Users 2 Posts: 695 ✭✭✭


    Public Function FindFile(ByVal sFolder As String, sFileExtension As String)
    
    Dim obFolder As Folder
    Dim obFile As File
    Dim fso As New FileSystemObject
    
    Set obFolder = fso.GetFolder(sFolder)
    
    For Each obFile In obFolder.Files
        If Right(obFile.Name, 3) = sFileExtension Then
            frmSearching.lstFilesFound.AddItem (obFolder.Path & obFile.Name)
        End If
    Next
    
    End Function
    

    This gives a "Invalid Procedure Call".

    Heres an example of the Call

    Call FindFile("C:\test\, "jpg")

    I'm pretty novice with VB, and sorry for the lack of comments but it drives me insane as everytime i go to add one somewhere in the code I add // instead of ' and PING msgbox error annoys the hell outta me so I kinda gave up on them :p


Comments

  • Closed Accounts Posts: 3,357 ✭✭✭Beano


    which line in the findfile function give you the error?


  • Registered Users, Registered Users 2 Posts: 2,781 ✭✭✭amen


    try
    [PHP]Call FindFile("C:\test\", "jpg")[/PHP]

    note the extra quotes


  • Registered Users, Registered Users 2 Posts: 15,443 ✭✭✭✭bonkey


    Is \ picked up in VB as an "escape" character like in many other languages? (Been a while since I did VB so I can't remember.)

    If so, then you'll need "c:\\test\\" as your path.
    it drives me insane as everytime i go to add one somewhere in the code I add // instead of ' and PING msgbox error
    I'm pretty sure that if you check the Options/Preferences options, you can tell VB to stop msgboxing you on errors. It should then highlight the line in red to tell you that you've gotten something wrong, but leave it at that.

    If you can't...its still no excuse for not commenting code.


  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    Do it without the trailing \ and also the call includes quotes around each string

    Because you have declared it as 2 string types as parameters

    If you have Norton AV or McAfee check that they are not blocking the FSO because I have seen that happen and the FSO cannot be used unless you dis allow script blocking


  • Registered Users, Registered Users 2 Posts: 2,777 ✭✭✭shanew


    DaSilva wrote:
    Public Function FindFile(ByVal sFolder As String, sFileExtension As String)
    
    Dim obFolder As Folder
    Dim obFile As File
    Dim fso As New FileSystemObject
    
    Set obFolder = fso.GetFolder(sFolder)
    
    For Each obFile In obFolder.Files
        If Right(obFile.Name, 3) = sFileExtension Then
            frmSearching.lstFilesFound.AddItem (obFolder.Path & obFile.Name)
        End If
    Next
    
    End Function
    

    This gives a "Invalid Procedure Call".

    Heres an example of the Call

    Call FindFile("C:\test\, "jpg")

    I'm pretty novice with VB, and sorry for the lack of comments but it drives me insane as everytime i go to add one somewhere in the code I add // instead of ' and PING msgbox error annoys the hell outta me so I kinda gave up on
    them :p


    I dont use Scripting - but below is a non-scripting version of your Function


    Shane.
    Public Function FindFile(ByVal sFolder As String, sFileExtension As String) as Boolean
    
    Dim sFile as String
    
    sFile = Dir$(sFolder & "\*." & sFileExtension, vbNormal)
    
    Do While sFile <> ""
    
            frmSearching.lstFilesFound.AddItem (sFolder & "\" &  sFile)
    
            sFile = Dir$
    Loop
    
    FindFile = True
    
    End Function
    


  • Advertisement
Advertisement