Results 1 to 10 of 10

Thread: Need help with Directories

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2000
    Posts
    85

    Question

    VB Code:
    1. Public Function FileFinder(WatchDir As String) As String
    2. 'this function will find the file, if it does not find the file
    3. 'that means that it is correct, they have never sent us this file
    4. 'before
    5. Dim FileFinding As String
    6. Dim count As Integer
    7. Dim counts As String
    8. Dim result As Long
    9. Dim string2 As String
    10. Dim CaptionValue As Integer
    11. Dim Preferences As String
    12. Dim FileToDelete As String
    13. Dim DeleteMe As Boolean
    14.  
    15. count = 0
    16.  
    17. FileFinding = Dir(WatchDir) 'Where to look for.
    18. Do Until FileFinding = ""
    19.  
    20.     count = count + 1
    21.     FileName = FileFinding
    22.  
    23.     If PreferencesDelimitor <> "" Then
    24.         string2 = PreferencesDelimitor
    25.         result = AmtInStr(FileName, string2)
    26.         Preferences = PreferencesFileFormat - 1
    27.         If result <> Preferences Then
    28.             CaptionValue = 2
    29.             StatusCaptionCase (CaptionValue)
    30.             MoveFileTemp (FileName)
    31.         End If
    32.     Else
    33.         MsgBox ("You MUST choose a Delimitor and File Format")
    34.         Combo1.SetFocus
    35.     End If
    36.    
    37.     FileFinding = Dir 'this is where error occurs
    38.    
    39.     If result = Preferences Then
    40.         MoveFiles (FileName)
    41.         FileToDelete = FileName
    42.         DeleteMe = True
    43.     End If
    44.    
    45.     If DeleteMe = True Then
    46.         DeleteFileName (FileToDelete)
    47.         DeleteMe = False
    48.     End If
    49. Loop
    50.  
    51. counts = CStr(count)
    52. FileFinder = counts
    53. End Function
    I have the above function. It works, almost, when the file it is searching for is found it does what it is supposed to do until it reaches the end of the directory list and then it comes back with this error: Run-Time error '5': Invalid procedure call or argument. If it does not find the file then everything works fine. It stops working on FileFinding = Dir.

    Any suggestions??
    Last edited by Hack; Apr 5th, 2006 at 06:20 AM. Reason: Added [vbcode][/vbcode] tags for more clarity.
    Using VB6 Still Pluging away

  2. #2
    Fanatic Member HaxSoft's Avatar
    Join Date
    May 2000
    Location
    Ohio
    Posts
    593

    Angry Maybe this is it!

    If you just call the Dir function without specifying a search mask -- for instance "*.*" -- the first time, then you get an error.

    Try this:
    Code:
    Private Sub Form_Load()
    
      Dim a As String
      a = Dir
      
    End Sub
    What happens?

    Yes... you get that same error: Run-time Error 5. This suggests to me that your program somehow resets the Dir function. Maybe one of those other functions you call in the loop are using calls to Dir. If that is the case, maybe that is your problem.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2000
    Posts
    85
    I don't think so, but let me check.
    Using VB6 Still Pluging away

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jun 2000
    Posts
    85

    Wink

    Thanks that is the problem.
    Using VB6 Still Pluging away

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jun 2000
    Posts
    85

    Angry

    Nope that was not it, still getting the same error
    Using VB6 Still Pluging away

  6. #6
    Fanatic Member HaxSoft's Avatar
    Join Date
    May 2000
    Location
    Ohio
    Posts
    593

    Unhappy

    hmm, Are you using any API calls or anything funny like that?

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jun 2000
    Posts
    85
    no. It was working fine this morning and then I added the delete calls and ever since then it has not worked.
    Using VB6 Still Pluging away

  8. #8
    Fanatic Member HaxSoft's Avatar
    Join Date
    May 2000
    Location
    Ohio
    Posts
    593
    Hmm, that sounds really weird. I have not had that problem ever. But listen, can you post the code in the DeleteFileName function? I think there is something in there that messes up your code.

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Jun 2000
    Posts
    85
    Sure, here it is.
    VB Code:
    1. Private Sub DeleteFileName(DeletedFile As String)
    2. Dim FilePath As String
    3.  
    4. FilePath = GetFiles & DeletedFile
    5. Kill FilePath
    6.  
    7. End Sub
    Here is the AmountInStr Function:
    VB Code:
    1. Public Function AmtInStr(String1 As String, string2 As String) As Long
    2. ', string3 As String, string4 As String
    3. 'this function counts the number of "." or "_" or "-" in the file name
    4. 'this is to know which company the file belongs to
    5.  
    6.     Dim Loop1 As Long, Amount As Integer
    7.     Amount% = 0
    8.  
    9.     For Loop1& = 1 To Len(String1$)
    10.         If InStr(Loop1&, String1$, string2$) <> 0 Then
    11.             Loop1& = InStr(Loop1&, String1$, string2$)
    12.             Amount% = Amount% + 1
    13.         End If
    14.  
    15.     DoEvents
    16.     Next Loop1&
    17.     AmtInStr& = Amount%
    18. End Function
    I have also included MoveFile and MoveFileTemp:
    VB Code:
    1. Public Function MoveFiles(MoveFileName As String)
    2. 'this is the function that is going to do all of the work
    3. 'this function will take the filename that has come in and
    4. 'find it's directory using the explore function, if a directory
    5. 'is not found then one will be created
    6. 'it will then try to find the filename of the file that it is
    7. 'looking for, if one is found then this will generate and error
    8. 'if no file is found the the filename will be moved and success has
    9. 'been made
    10. Dim result As String
    11. Dim count As Integer
    12. Dim answer As Integer
    13. Dim FilePath As String
    14. Dim NewFilePath As String
    15. Dim AlreadyThere As String
    16. Dim ActionValue As Integer
    17. Dim CaptionValue As Integer
    18.    
    19. FilePath = GetFiles & MoveFileName
    20. NewFilePath = MoveLocation & MoveFileName
    21. CaptionValue = 2
    22. StatusCaptionCase (CaptionValue)
    23.  
    24. If MoveFileName = "" Then
    25.     result = FileFinder(GetFiles)
    26.     count = CInt(result)
    27.     count = count - 1
    28.     FileCopy FilePath, NewFilePath
    29.     answer = 1
    30. Else
    31.     'FileCopy FilePath, NewFilePath
    32.     'if there is this file in the directory already then
    33.     'raise and error and do not move the file
    34.     'need to create the new folder name, which is the opp number
    35.     'which is the first set of numbers before the first deliminitor
    36.     SaveFile (MoveFileName)
    37.     answer = 1
    38.  
    39.     ActionValue = answer
    40.     If ActionValue = 3 Or ActionValue = 4 Then
    41.         CaptionValue = 3
    42.         StatusCaptionCase (CaptionValue)
    43.  
    44.     Else
    45.         CaptionValue = 0
    46.         StatusCaptionCase (CaptionValue)
    47.  
    48.     End If
    49.     'write to the lstReport what was done
    50.     'example "Moved file from here to there
    51.     ActionCase (ActionValue)
    52.     lstFile.AddItem FileName
    53. End If
    54.  
    55. End Function
    56.  
    57. Public Function MoveFileTemp(MoveToTempFileName As String)
    58. Dim result As String
    59. Dim count As Integer
    60. Dim answer As Integer
    61. Dim FilePath As String
    62. Dim NewFilePath As String
    63. Dim AlreadyThere As String
    64. Dim ActionValue As Integer
    65. Dim CaptionValue As Integer
    66.    
    67. FilePath = GetFiles & MoveToTempFileName
    68. NewFilePath = MoveTempLocation & MoveToTempFileName
    69. CaptionValue = 2
    70. StatusCaptionCase (CaptionValue)
    71.  
    72. If MoveToTempFileName = "" Then
    73.     result = FileFinder(GetFiles)
    74.     count = CInt(result)
    75.     count = count - 1
    76.     FileCopy FilePath, NewFilePath
    77.     answer = 1
    78. Else
    79.     FileCopy FilePath, NewFilePath
    80.     'if there is this file in the directory already then
    81.     'raise and error and do not move the file
    82.     answer = 5
    83.     ActionValue = answer
    84.     If ActionValue = 3 Or ActionValue = 4 Then
    85.         CaptionValue = 3
    86.         StatusCaptionCase (CaptionValue)
    87.  
    88.     Else
    89.         CaptionValue = 0
    90.         StatusCaptionCase (CaptionValue)
    91.  
    92.     End If
    93.     'write to the lstReport what was done
    94.     'example "Moved file from here to there
    95.     ActionCase (ActionValue)
    96.     lstError.AddItem FileName
    97. End If
    98.  
    99. End Function
    Last edited by Hack; Apr 5th, 2006 at 06:23 AM. Reason: Added [vbcode] [/vbcode] tags or more clarity.
    Using VB6 Still Pluging away

  10. #10
    Lively Member
    Join Date
    Feb 2006
    Posts
    69

    Re: Need help with Directories

    Hi,
    It happen to me the same think while my program in the loop for wating to any file come to the directory to do some process with it, which i work around it by puting another if statment
    if oldfilename <> "" then
    do wait time
    end if
    i think some time the cpu is fast which it do 2 process in the same time..looking at the file even no file and doing other function. which indecate the file in use or lock or even not there.
    bye

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