如何知道Inet下载文件的进度
2006-10-31 23:01
316 查看
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
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
相关文章推荐
- NSURLConnection下载文件时,如何显示进度
- 知道如何上去?也得知道如何下来--Struts 2 下载文件(13)
- urlretrieve 如何给文件下载设置下载进度?
- Android中如何下载文件并显示下载进度
- android中如何下载文件并显示下载进度
- 安卓下载文件如何更新UI进度
- android中如何下载文件并显示下载进度
- 蓝牙传输文件,如何知道进度和传输完成
- 用idhttp打开网页或下载文件时如何显示进度
- NSURLConnection下载文件时,如何显示进度
- python中如何使用requests模块下载文件并获取进度提示?
- LoadRunner中如何验证下载的文件大小、统计下载时间、度量下载速度?
- Windows客户端开发--URLDownloadToFile下载文件进度条
- 如何免费下载高程数据并生成TIF文件
- 利用curl下载文件(进度条显示) 代码片段
- 如何在Webstorm/Phpstorm中设置连接FTP,并快速进行文件比较,上传下载,同步等操作
- OkHttp学习(2)-->>异步下载图片、文件(拦截器重写Response方法实现下载进度获取)
- 如何利用GCD Group批量下载文件
- 【JAVA-OSS】如何在spring-boot项目中使用oss上传下载文件
- 下载apk文件在/data/data/packagename/files/目录下,如何安装成功