如何知道Inet下载文件的进度

来源:互联网 发布:java打印123直角三角形 编辑:程序博客网 时间:2024/04/30 10:56
Dim LastTextBox As TextBox

Dim TotalLength As Long
Dim Step As Single

Private Sub Command1_Click()
Dim File() As Byte
File() = Inet1.OpenURL(Text1.Text, icByteArray)
Open "C:/1.zip" For Binary Access Write As #1
Put #1, , File()
Close #1
MsgBox "Success"
End Sub

Private Sub Command2_Click()
Inet1.Execute Text1.Text, "GET"
End Sub

Private Sub Form_Load()
Text1.Text = "http://www14.brinkster.com/weblover/media2db.zip"
End Sub

Private Sub Inet1_StateChanged(ByVal State As Integer)
Dim vtData() As Byte '数据变量。
Dim Count As Long
Select Case State
Case icHostResolvingHost
Label1.Caption = "正在查询所指定的主机的 IP 地址"
Case icHostResolved
Label1.Caption = "成功地找到所指定的主机的 IP 地址"
Case icConnecting
Label1.Caption = "正在与主机连接"
Case icConnected
Label1.Caption = "已与主机连接成功"
Case icRequesting
Label1.Caption = "正在向主机发送请求"
Case icRequestSent
Label1.Caption = "发送请求已成功"
Case icReceivingResponse
Label1.Caption = "在接收主机的响应"
Case icResponseReceived
Label1.Caption = "成功地接收到主机的响应"
Case icDisconnecting
Label1.Caption = "正在解除与主机的连接"
Case icDisconnected
Label1.Caption = "已成功地与主机解除了连接"
Case icError
Label1.Caption = "与主机通讯时出现了错误"
Case icResponseCompleted '12

TotalLength = Val(Inet1.GetHeader("Content-length"))
Step = (Me.ScaleWidth - Picture1.Left * 2) / TotalLength
Debug.Print Step
Label1.Caption = "请求已经完成,并且所有数据均已接收到"
Open "C:/1.zip" For Binary Access Write As #1
vtData = Inet1.GetChunk(1024, icByteArray)
Count = 1000
Picture1.Width = Picture1.Width + Count * Step
Label1.Caption = "" & Round(Count * 1000 / TotalLength, 0) & "%"
'Me.Refresh
Do While UBound(vtData) > 0
Put #1, , vtData
vtData = Inet1.GetChunk(1024, icByteArray)
Picture1.Width = Picture1.Width + 1024 * Step
Count = Count + 1024
Label2.Caption = "" & Round(Count * 100 / TotalLength, 0) & "%"
Loop
Put #1, , vtData
Close #1
Label2.Caption = "100%"
MsgBox "下载完成"
End Select
End Sub
 
原创粉丝点击