[RESOLVED] GetAttr Err.Number = 5 ?-VBForums
Results 1 to 7 of 7

Thread: [RESOLVED] GetAttr Err.Number = 5 ?

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2006
    Posts
    3

    Resolved [RESOLVED] GetAttr Err.Number = 5 ?

    Hi,

    I'm new to this forum, i encountered an err.number = 5 when i tried to use GetAttr() on a file path. I used this GetAttr() in a For loop. I tried looking many places but msdn only mentions about error 52 and 53, no mention of 5 was found. Can anyone help? Is there any place where i can get a full list of error codes for GetAttr()?
    Thanks! Below is my code for reference.

    Peter

    VB Code:
    1. Public Function fnFindTargetComp(arrInTargetComp) As Boolean
    2.     Dim Filename$, i, res As Boolean
    3.     Dim vAttr
    4.    
    5.     Err.Clear
    6.     On Error GoTo ErrorHandler
    7.  
    8.     For i = 0 To UBound(arrInTargetComp)
    9.         Filename$ = "C:\FASIP\" & Trim$(arrInTargetComp(i)) & ".hex"
    10.         ' Get the attributes and ensure that it isn't a directory
    11.         vAttr = GetAttr(Filename$)
    12.         fnFindTargetComp = ((vAttr And vbDirectory) <> vbDirectory)
    13.         dbg (Filename$)
    14.     Next i
    15.    
    16.     Exit Function
    17.  
    18. ErrorHandler:
    19.     Select Case Err.Number
    20.         Case 52    ' Pathname is invalid or contains wildcards
    21.             MsgBox ("File :" & Filename$ & "has invalid pathname or contains wildcards.")
    22.         Case 53    ' Target file does not exist
    23.             MsgBox ("File :" & Filename$ & "does not exist.")
    24.         Case Else
    25.             MsgBox ("File : Unknown error")
    26.     End Select
    27.  
    28. End Function
    Last edited by MartinLiss; Oct 8th, 2006 at 10:24 AM.

  2. #2

    Thread Starter
    New Member
    Join Date
    Sep 2006
    Posts
    3

    Re: GetAttr Err.Number = 5 ?

    Just to clarify, the err.number = 5 occurs only at the final loop. Pls help, thanks.

  3. #3

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    32,865

    Re: GetAttr Err.Number = 5 ?


    Error 5 is not specific to GetAttr but rather its a general purpose error "Invalid procedure call or argument".

    BTW I added vbcode tags to make your code easier to read.

  5. #5

  6. #6

    Thread Starter
    New Member
    Join Date
    Sep 2006
    Posts
    3

    Talking Re: GetAttr Err.Number = 5 ?

    Hi,

    Thanks for all the replies, i've managed to find out why, and it's rather careless of me.
    The filename$ looks perfectly ok to me when i add it to watch when debugging. However, when i try to print it out, it became apparent to me.
    It looks something like this:
    "abcdefg .hex"
    instead of:
    "abcdefg.hex"
    The spaces before .hex is actually tabs, not white spaces, that's why my trim$() doesn't work on it. (i hope i'm right that trim$ only trims away white spaces but not tabs)

    Thanks again folks, might need help again next time round

  7. #7

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.