Results 1 to 6 of 6

Thread: Error not being caught (RTE 76)

Hybrid View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2012
    Posts
    27

    Re: Error not being caught (RTE 76)

    Quote Originally Posted by RhinoBull View Post
    Are you sure you suppose to get err.number 76?
    Comment out "If Err.Number = 76 Then" and do debug.print err.number instead so you can get actual error number.
    Then make your decision how to handle it based on what you find.

    Also, few comments regarding your code:

    - try not to use labels (start, etc...)
    - try not to use reserved words (Err) for anything you do within your code...
    The error isn't being handled so I don't see how commenting out the if statement will have any effect. (I went line by line so I am pretty sure the label isn't being reached.)
    Try the following modifications:

    Code:
    Public Sub DownloadFile(ByRef sURL As String, ByRef sFilePath As String)
    Dim bytData() As Byte
    Dim FN As Integer
    Dim sDir As String

    bytData() = Form1.inetDownload.OpenURL(sURL, icByteArray)

    'Extract the path component of the fully-qualified file path
    sDir = Left$(sFilePath, InStrRev(sFilePath, "\") - 1&)

    If Not PathExists(sDir) Then
    MkDirEx sDir '<-- Click this
    ElseIf FileExists(sFilePath) Then
    Kill sFilePath
    End If

    FN = FreeFile
    Open sFilePath For Binary Access Write As FN
    Put #FN, , bytData()
    Close FN
    End Sub

    Public Function FileExists(ByRef sFile As String) As Boolean
    On Error Resume Next
    FileExists = (GetAttr(sFile) And vbDirectory) <> vbDirectory
    End Function

    Public Function PathExists(ByRef sPath As String) As Boolean
    On Error Resume Next
    PathExists = (GetAttr(sPath) And vbDirectory) = vbDirectory
    End Function
    You may also want to check out the URLDownloadToFile API function. Search this forum for examples of using it.
    Thank you. I'll try that. And thanks for the API, I'll look into it.

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Error not being caught (RTE 76)

    Quote Originally Posted by abhi2011 View Post
    The error isn't being handled so I don't see how commenting out the if statement will have any effect. (I went line by line so I am pretty sure the label isn't being reached.)
    Your original post isn't clear at all. The way I interpreted, you're getting error but not not the one you expected.
    Whether or label was reached isn't relevant... Perhaps you learn from Bonnie's code sample how to code better (or cleaner if you will).

    Good luck.

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