From: Gilles Ganault on

I found some code on the Net that lets me download files with
HTTP through the MSINET.OCX control. This program is used to update an
application automatically when the user logs on.

Problem is, I get an Err 13/Type Mismatch after successfully
downloading the first file of two.

For some reason, the error goes away if I display a MsgBox between the
two calls to the downloading routine. FWIW, I'm using VB5 and
Private Sub Download(source As String, target As String)
Dim Size As Long, Remaining As Long, FFile As Integer, Chunk() As

Inet1.Execute source, "GET"
Do While Inet1.StillExecuting

Size = CLng(Inet1.GetHeader("Content-Length"))
Remaining = Size

FFile = FreeFile
Open target For Binary Access Write As #FFile
Do Until Remaining = 0
If Remaining > 1024 Then
Chunk = Inet1.GetChunk(1024, icByteArray)
Remaining = Remaining - 1024
Chunk = Inet1.GetChunk(Remaining, icByteArray)
Remaining = 0
End If
Label1.Caption = "Downloading " & source & vbCrLf & _
"Remaining " & CStr(Remaining) & " bytes"
Put #FFile, , Chunk
Close #FFile
End Sub

Private Sub Form_Activate()
Call Download("", "c:\file1.exe")

'If commented out, VB runtime error "13" type mismatch
'MsgBox "here"

Call Download("", "c:\file2.exe")

End Sub

Any idea what it wrong?

Thank you.