From: Gilles Ganault on 12 Nov 2007 19:13 Hello 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 MSINET.OCX 6.1.97.82: ============ Private Sub Download(source As String, target As String) Dim Size As Long, Remaining As Long, FFile As Integer, Chunk() As Byte Inet1.Execute source, "GET" Do While Inet1.StillExecuting DoEvents Loop 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 Else Chunk = Inet1.GetChunk(Remaining, icByteArray) Remaining = 0 End If Label1.Caption = "Downloading " & source & vbCrLf & _ "Remaining " & CStr(Remaining) & " bytes" Put #FFile, , Chunk Loop Close #FFile End Sub Private Sub Form_Activate() Call Download("http://www.acme.com/file1.exe", "c:\file1.exe") 'If commented out, VB runtime error "13" type mismatch 'MsgBox "here" Call Download("http://www.acme.com/file2.exe", "c:\file2.exe") End End Sub ============ Any idea what it wrong? Thank you.
|
Pages: 1 Prev: Trouble with setting cursor at mouse-click Next: SxS DLL location |