From: Gilles Ganault on 12 Nov 2007 19:13
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
Label1.Caption = "Downloading " & source & vbCrLf & _
"Remaining " & CStr(Remaining) & " bytes"
Put #FFile, , Chunk
Private Sub Form_Activate()
Call Download("http://www.acme.com/file1.exe", "c:\file1.exe")
'If commented out, VB runtime error "13" type mismatch
Call Download("http://www.acme.com/file2.exe", "c:\file2.exe")
Any idea what it wrong?