Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations danielledunham on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CHECK if download is without error

sal21

Programmer
Joined
Apr 26, 2004
Messages
507
Location
IT
Rich (BB code):
Public Function DownloadFile_WEB(sURL As String, _
                                 sDestPath As String, _
                                 sDestFileName As String) As Boolean

'https://www.anagrafenazionale.interno.it/wp-content/uploads/ANPR_archivio_comuni.csv

'Se il download va a buon fine restituisce True

    Dim WinHttpReq As Object
    Dim oStream As Object
    Dim sBody As Variant
    Set WinHttpReq = CreateObject("MSXML2.XMLHTTP")

    On Error Resume Next

    With WinHttpReq
    
        .setTimeouts 50000, 50000, 50000, 50000
        
        .Open "GET", sURL, False
        .Send

        If .Status = 200 Then
        
            sBody = .responseBody
            Set oStream = CreateObject("ADODB.Stream")

            With oStream
                .Open

                .Type = 1
                .Write sBody

                If Right(sDestPath, 1) <> "" Then
                    sDestPath = sDestPath & ""
                End If

                .SaveToFile sDestPath & sDestFileName, 2    '2 sovrascrive

                .Close

            End With
            
        End If

    End With
    

    Set WinHttpReq = Nothing
    Set oStream = Nothing
    
    Call LEGGI_FILE

End Function

I need to check if i can call LEGGI_FILE


actually is to the and of code but sure not is a correct choice...
 
>CHECK if download is without error
>Check if i can call LEGGI_FILE

These are two different things. What precisely is it that you need to actually do?
 
If I remember correctly, this function returns a boolean value, and the way you have it coded, it always returns false. I don't see where you set the function to true.

In short, this function is a pass or fail. It either works or doesn't, and should return that knowledge. However, it seems you are afraid of a zero-length file and you want to check for it (I guess) with the LEGGI_FILE. If this is true, and what you want to do, then you can use something like Variable = Filelen(Path) and check to see if the "Variable" > 0.

You do not need to call another function to check for this. You can do it in this function, and once you determine that you don't have a zero-length file, you can return the T/F value.

Good Luck
 

Part and Inventory Search

Sponsor

Back
Top