Using the Internet Control to download a fair-sized file

Jezuit
Jezuit used Ask the Experts™
on
I'm trying to use the Internet Control to download a file that's about 240 kb. The problem is I use the code below, and it only downloads about 400 bytes of it and then moves on to the next bit of code




    Dim YesNo As VbMsgBoxResult
    Dim Current As Variant
    Dim Update As Variant
    Dim Minor As Variant
    Dim Major As Variant
    Dim Revised As Variant
   
    Dim ff() As Byte
    Dim Info As Integer

   With Inet1
        List1.AddItem "Downloading update.txt file to locate current updates"
        ff = .OpenURL("http://library.gitgear.com/update.txt", icByteArray)
    End With
   
    Info = FreeFile
    Open "C:\update.txt" For Binary As #Info
        Put #Info, 1, ff
        List1.AddItem "Update.txt file downloaded successfully"
    Close #Info
   
    Open "C:\Program Files\UltimateLibrary\current.txt" For Input As #Info
        Input #Info, Current
        List1.AddItem "Scanning current version"
    Close #Info
   
    Open "C:\update.txt" For Input As #Info
        Input #Info, Update
    Close #Info
   
    If Update > Current Then
        YesNo = MsgBox("There is a new version available. Would you like to download it now?", vbYesNo, "New Version")
    Else
        MsgBox "There are no new updates available at this time."
        Unload Me
    End If
   
    If YesNo = vbYes Then
       With Inet1
           List1.AddItem "Downloading new program file. Please wait while the download finishes."

       'It shouldn't pass the next step until it's fully downloaded all 240 kb
           ff = .OpenURL("http://library.gitgear.com/Ultimate.exe", icByteArray)
       End With
       
       Info = FreeFile
       Open "C:\update.txt" For Binary As #Info
            Put #Info, 1, ff
           List1.AddItem "Download complete, naming and removing"
       Close #Info
   
       Unload Me
   End If


This is more or less a bunch of code that was found by doing tons of searches, and I've tried fiddling around with it to see how it works, but it's not really making a difference. Anyone have any ideas?

Jez
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
First of all, the file your willing to download does not exist. Maybe thats your problem.

Author

Commented:
hold on a sec, I'll change it... I changed it on purpose earlier to try and see if something stupid was the problem

Commented:
Try this piece of code, its less code :

Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Public Function DownloadFile(URL As String, LocalFilename As String) As Boolean
    Dim lngRetVal As Long
    lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
    If lngRetVal = 0 Then DownloadFile = True
End Function
Private Sub Form_Load()
    Const Source As String = "http://library.gitgear.com/Ultimate.exe"
    Const Target As String = "c:\ultimate.exe"
    DownloadFile Source, Target
End Sub
Should you be charging more for IT Services?

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
Okay, it should be there now...

Author

Commented:
I thought that urlmon was only for html files.... hrm.... guess I was stupid. Lemme give that a shot real quick.
Commented:
You can compare the file versions instead of using textdocuments ( I made the entire update code for you )

Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Public Function DownloadFile(URL As String, LocalFilename As String) As Boolean
    Dim lngRetVal As Long
    lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
    If lngRetVal = 0 Then DownloadFile = True
End Function
Private Sub Form_Load()
    Const Source As String = "http://library.gitgear.com/Ultimate.exe"
    Const Target As String = "c:\ultimate.exe"
    Dim Temp As String
        Temp = Replace(Environ$("TEMP") & "\" & "ultimate.exe", "\\", "\")
    DownloadFile Source, Temp
    If GetVersion(Target) <> GetVersion(Temp) Then
        tmp = MsgBox("Update is neccesarry, klik ok to download or cancel to abort", vbOKCancel, "Update Information")
        If tmp = vbOK Then
            Kill Target
            FileCopy Temp, Target
            Kill Temp
            MsgBox "Update is completed"
        Else
            Exit Sub
        End If
    Else
        MsgBox "File is up to date, update are not required", vbOKOnly, "Update information"
    End If
End Sub

Function GetVersion(fname As String) As String
    Set fso = CreateObject("Scripting.FileSystemObject")
    GetVersion = fso.GetFileVersion(fname)
    Set fso = Nothing
End Function

Happy programming,
Ayhan Elatik

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial