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

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
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值