分类:
2009-04-13 10:25:43
进度条可以用ProgressBar在Inet的StateChanged事件里面实现
给你个例子先看看
Private m_lngDocSize As Long
Private Const strURL = ""
Private Const FileName = "inet.rar"
Private Sub Command1_Click()
Call start
End Sub
Private Sub Inet1_StateChanged(ByVal State As Integer)
Dim binBuffer() As Byte
Dim sngProgerssValue As Single
Dim iBlock As Long
On Error Resume Next
iBlock = 0
Select Case State
Case icResponseCompleted
Command2.Enabled = False
'打开文件供写入
Open App.path & "\" & FileName For Binary Access Write As #1
Do '从缓冲区读取数据
DoEvents
binBuffer = Inet1.GetChunk(512, icByteArray)
'strText = strText & strBuffer
iBlock = iBlock + 1
If m_lngDocSize > 0 Then
'获得进度百分比值
sngProgerssValue = Int((iBlock * 512 / m_lngDocSize) * 100)
'更新进度标签显示内容
lblProgressInfo.Caption = "已下载 " & CStr(iBlock * 512) & " 字节 (" & CStr(sngProgerssValue) & "%)"
'用新值更新进度条控件
ProgressBar1.Value = sngProgerssValue
'写入文件
Put #1, , binBuffer()
End If
Loop Until iBlock * 512 >= m_lngDocSize
'关闭文件
Close #1
MsgBox "升级完成", vbOKOnly Or vbInformation, "在线升级"
lblProgressInfo.Caption = ""
Command2.Enabled = True
Case icResponseReceived
If m_lngDocSize = 0 Then
'读取页面文件大小
If Len(Inet1.GetHeader("Content-Length")) > 0 Then
m_lngDocSize = CLng(Inet1.GetHeader("Content-Length"))
If (m_lngDocSize = 0) Then
' MsgBox "读取远程数据出错", vbOKOnly Or vbExclamation, "在线升级"
lblProgressInfo.Caption = ""
Call start
End If
Else 'NOT LEN(INET1.GETHEADER("CONTENT-LENGTH"))...
'MsgBox "ERROR!", vbOKOnly Or vbExclamation, "在线升级"
lblProgressInfo.Caption = ""
Call start
End If
End If
Case icError
'MsgBox "与主机通信出错", vbOKOnly Or vbExclamation, "在线升级"
lblProgressInfo.Caption = ""
Call start
Case icResolvingHost
lblProgressInfo.Caption = "正在查找主机..."
Case icHostResolved
lblProgressInfo.Caption = "已经找到主机"
Case icConnecting
lblProgressInfo.Caption = "正在联系主机"
Case icConnected
lblProgressInfo.Caption = "已经连接到主机"
Case icRequesting
lblProgressInfo.Caption = "正在发送请求..."
Case icRequestSent
lblProgressInfo.Caption = "成功发送请求"
Case icReceivingResponse
lblProgressInfo.Caption = "正在接收回应..."
Case icDisconnecting
lblProgressInfo.Caption = "正在断开连接..."
Case icDisconnected
lblProgressInfo.Caption = "已经断开连接"
End Select
End Sub
Sub start()
'文件大小值复位
m_lngDocSize = 0
'复位进度条控件
ProgressBar1.Value = 0.001
'显示进度的标签内容设为空
lblProgressInfo.Caption = ""
'定义ITC控件使用的协议为HTTP协议
Inet1.Protocol = icHTTP
'调用Execute方法向Web服务器发送HTTP请求
Inet1.Execute Trim$(strURL), "GET"
lblProgressInfo.Caption = "请等待..."
End Sub