VB中inet控件的用法? 150
PrivateSubInet1_StateChanged(ByValStateAsInteger)OnErrorGoTovberr1DimbinBuffer()AsByt...
Private Sub Inet1_StateChanged(ByVal State As Integer)
On Error GoTo vberr1
Dim binBuffer() As Byte
Dim sngProgerssValue As Single
Dim iBlock As Long
On Error Resume Next
iBlock = 0
Select Case State
Case icResponseCompleted
Open App.path & "\" & downName For Binary Access Write As #1
Do
DoEvents
binBuffer = Inet1.GetChunk(512, icByteArray)
iBlock = iBlock + 1
If m_lngDocSize > 0 Then
sngProgerssValue = Int((iBlock * 512 / m_lngDocSize) * 100)
fzt.Caption = "已下载 " & CStr(iBlock * 512) & " 字节 (" & CStr(sngProgerssValue) & "%)"
P.Value = sngProgerssValue
Put #1, , binBuffer()
End If
Loop Until iBlock * 512 >= m_lngDocSize
Close #1
zxqk.Text = "下载完成!"
If Right(www2.Text, 3) = "rar" Then Call setup_Click
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
fzt.Caption = ""
Call start
End If
Else
fzt.Caption = ""
Call start
End If
End If
Case icHostResolvingHost
zzt.Caption = "正在查询所指定的主机的 IP 地址"
Case icHostResolved
zzt.Caption = "成功地找到所指定的主机的 IP 地址"
Case icConnecting
zzt.Caption = "正在与主机连接"
Case icConnected
zzt.Caption = "已与主机连接成功"
Case icRequesting
zzt.Caption = "正在向主机发送请求"
Case icRequestSent
zzt.Caption = "发送请求已成功"
Case icReceivingResponse
zzt.Caption = "在接收主机的响应"
Case icResponseReceived
zzt.Caption = "成功地接收到主机的响应"
Case icDisconnecting
zzt.Caption = "正在解除与主机的连接"
Case icDisconnected
zzt.Caption = "已成功地与主机解除了连接"
Case icError
zzt.Caption = "与主机通讯时出现了错误"
End Select
Exit Sub
vberr1:
MsgBox "测试失败!", vbOKOnly + vbCritical, "提示!"
MsgBox "原因:" & Err.Description, vbOKOnly + vbCritical, "提示!"
End Sub
为什么我用Inet1.OpenURL wwwbb + www + wwwcc + "system.txt"打开文本文件的时侯,如果加上以上代码(主要用来在线升级下截rar类文件),就会卡住呢,大侠们有什么好的办法啊?
是有时会卡住,我把这段代码删除就好了,是不是要加个延时之类的东东啊,大侠帮帮忙啊? 展开
On Error GoTo vberr1
Dim binBuffer() As Byte
Dim sngProgerssValue As Single
Dim iBlock As Long
On Error Resume Next
iBlock = 0
Select Case State
Case icResponseCompleted
Open App.path & "\" & downName For Binary Access Write As #1
Do
DoEvents
binBuffer = Inet1.GetChunk(512, icByteArray)
iBlock = iBlock + 1
If m_lngDocSize > 0 Then
sngProgerssValue = Int((iBlock * 512 / m_lngDocSize) * 100)
fzt.Caption = "已下载 " & CStr(iBlock * 512) & " 字节 (" & CStr(sngProgerssValue) & "%)"
P.Value = sngProgerssValue
Put #1, , binBuffer()
End If
Loop Until iBlock * 512 >= m_lngDocSize
Close #1
zxqk.Text = "下载完成!"
If Right(www2.Text, 3) = "rar" Then Call setup_Click
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
fzt.Caption = ""
Call start
End If
Else
fzt.Caption = ""
Call start
End If
End If
Case icHostResolvingHost
zzt.Caption = "正在查询所指定的主机的 IP 地址"
Case icHostResolved
zzt.Caption = "成功地找到所指定的主机的 IP 地址"
Case icConnecting
zzt.Caption = "正在与主机连接"
Case icConnected
zzt.Caption = "已与主机连接成功"
Case icRequesting
zzt.Caption = "正在向主机发送请求"
Case icRequestSent
zzt.Caption = "发送请求已成功"
Case icReceivingResponse
zzt.Caption = "在接收主机的响应"
Case icResponseReceived
zzt.Caption = "成功地接收到主机的响应"
Case icDisconnecting
zzt.Caption = "正在解除与主机的连接"
Case icDisconnected
zzt.Caption = "已成功地与主机解除了连接"
Case icError
zzt.Caption = "与主机通讯时出现了错误"
End Select
Exit Sub
vberr1:
MsgBox "测试失败!", vbOKOnly + vbCritical, "提示!"
MsgBox "原因:" & Err.Description, vbOKOnly + vbCritical, "提示!"
End Sub
为什么我用Inet1.OpenURL wwwbb + www + wwwcc + "system.txt"打开文本文件的时侯,如果加上以上代码(主要用来在线升级下截rar类文件),就会卡住呢,大侠们有什么好的办法啊?
是有时会卡住,我把这段代码删除就好了,是不是要加个延时之类的东东啊,大侠帮帮忙啊? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询