Link to home
Start Free TrialLog in
Avatar of thaburner
thaburnerFlag for United States of America

asked on

Download File/Show INET Speed

This is the code i use to download a file off webserver how can i get it to tell me the downoad Speed?

Private Sub inet1_StateChanged(ByVal State As Integer)
'On Error Resume Next
    Dim vtData()  As Byte ' As Variant
    Dim FreeNr    As Integer
    Dim SizeDone  As Long
    Dim bDone     As Boolean
    Dim GetPerc   As Integer
    Dim dSizeDone As Double
    Dim dFileSize As Double
   
    Select Case State ' ... Other cases not shown.
        Case icError: ' 11
            If Inet1.ResponseCode = 12007 Then
                NoInternetConnection Inet1.ResponseCode, Inet1.ResponseInfo
            End If
           
        Case icResponseCompleted: ' 12
            If m_GettingFileSize = True Then
                Exit Sub
            End If
           
            'hier zijn we afbeeldingen aan het downloaden
            If m_DownloadingFile = True Then
                FreeNr = FreeFile
               
                Open m_LocalSaveFile For Binary Access Write As FreeNr
               
                Do While Not bDone
                    vtData = Inet1.GetChunk(1024, icByteArray) ' Get next chunk.
                   
                    SizeDone = SizeDone + UBound(vtData)
                             
                    GetPerc = (SizeDone / m_DownloadingFileSize) * 100
                    If GetPerc > 100 Then GetPerc = 100
                    If GetPerc < 0 Then GetPerc = 0
                   
                    dFileSize = m_DownloadingFileSize
                    dSizeDone = SizeDone
                   
                    prgPercentDone.Value = GetPerc
                    Me.Caption = "(%" & GetPerc & ") Downloading Updates"
                   
                    lblProgress.Caption = "Progress: %" & GetPerc
                    lblProgress.Refresh
                    DoEvents
                    Put #FreeNr, , vtData()          
                    If UBound(vtData) = -1 Then
                        bDone = True
                    Else
                        DoEvents      
                    End If
                Loop
               
                Close FreeNr        
               
                    'MsgBox "File downloaded"
                    cmdStart.Caption = "&Start"
                    'CheckFiles
                    prgPercentDone.Value = 0    
            End If
    End Select
End Sub
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial