此程序第一次单击升级运行经常,但是你在第一次运行完后马上再单击升级按钮运行,就报不能完成请求错误,第一次连接好象没有关闭,我不知何故,特此请教,本人不兴感激!VERSION 5.00
Object = "{48E59290-9880-11CF-9754-00AA00C00908}#1.0#0"; "MSINET.OCX"
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form form1
BorderStyle = 1 'Fixed Single
Caption = "form1"
ClientHeight = 4140
ClientLeft = 45
ClientTop = 330
ClientWidth = 6420
ControlBox = 0 'False
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 4140
ScaleWidth = 6420
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command2
Caption = "退 出"
Height = 975
Left = 4680
Style = 1 'Graphical
TabIndex = 4
Top = 1200
Width = 1215
End
Begin VB.ListBox List1
Height = 3300
Left = 240
TabIndex = 2
Top = 120
Width = 4215
End
Begin MSComctlLib.ProgressBar ProgressBar1
Height = 375
Left = 120
TabIndex = 1
Top = 3600
Visible = 0 'False
Width = 6135
_ExtentX = 10821
_ExtentY = 661
_Version = 393216
Appearance = 1
End
Begin VB.CommandButton Command1
Caption = "升 级"
Height = 975
Left = 4680
Style = 1 'Graphical
TabIndex = 0
Top = 120
Width = 1215
End
Begin InetCtlsObjects.Inet Inet1
Left = 5280
Top = 2280
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
Protocol = 4
URL = "http://"
End
Begin VB.Label lblProgressInfo
Alignment = 2 'Center
AutoSize = -1 'True
Caption = "Label1"
Height = 180
Left = 5160
TabIndex = 3
Top = 2880
Width = 540
End
End
Attribute VB_Name = "form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option ExplicitDim acceptingdata As Long'该变量用于存储文件大小
Private m_lngExeSize As Long
Private Const strURL = " http://cnsubmit.com/download/downloadnow.exe"
Private Const FileName = "downloadnow.exe"Private Sub Command1_Click()
m_lngExeSize = 0
'定义ITC控件使用的协议为HTTP协议
Inet1.Protocol = icHTTP
Inet1.Execute Trim$(strURL), "GET"
End SubPrivate Sub Command2_Click()
Inet1.Cancel
Unload Me
End
End SubPrivate 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 icResponseReceived '''程序已成功接收完服务器的响应,读出文件的大小
If m_lngExeSize = 0 Then
'读取页面文件大小
If Len(Inet1.GetHeader("Content-length")) > 0 Then '''''为什么第二次运行这里总是出错?????
m_lngExeSize = CLng(Inet1.GetHeader("Content-length"))
End If
End If
Case icResponseCompleted ''''说明该请求已经完成,并且所有数据都已经接收完毕,可以从缓冲读数据了
'打开文件供写入
Open App.Path & "\" & FileName For Binary Access Write As #1 Do '从缓冲区读取数据
DoEvents
binBuffer = Inet1.GetChunk(512, icByteArray)
iBlock = iBlock + 1
If m_lngExeSize > 0 Then
If UBound(binBuffer) > 0 Then
'更新标签显示内容
lblProgressInfo.Caption = CStr(iBlock * 512) & " 字节 (" & CStr(sngProgerssValue) & "%)"
Put #1, , binBuffer()
End If
End If
Loop Until iBlock * 512 >= m_lngExeSize
'关闭文件
Close #1
End Select
End Sub
Object = "{48E59290-9880-11CF-9754-00AA00C00908}#1.0#0"; "MSINET.OCX"
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form form1
BorderStyle = 1 'Fixed Single
Caption = "form1"
ClientHeight = 4140
ClientLeft = 45
ClientTop = 330
ClientWidth = 6420
ControlBox = 0 'False
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 4140
ScaleWidth = 6420
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command2
Caption = "退 出"
Height = 975
Left = 4680
Style = 1 'Graphical
TabIndex = 4
Top = 1200
Width = 1215
End
Begin VB.ListBox List1
Height = 3300
Left = 240
TabIndex = 2
Top = 120
Width = 4215
End
Begin MSComctlLib.ProgressBar ProgressBar1
Height = 375
Left = 120
TabIndex = 1
Top = 3600
Visible = 0 'False
Width = 6135
_ExtentX = 10821
_ExtentY = 661
_Version = 393216
Appearance = 1
End
Begin VB.CommandButton Command1
Caption = "升 级"
Height = 975
Left = 4680
Style = 1 'Graphical
TabIndex = 0
Top = 120
Width = 1215
End
Begin InetCtlsObjects.Inet Inet1
Left = 5280
Top = 2280
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
Protocol = 4
URL = "http://"
End
Begin VB.Label lblProgressInfo
Alignment = 2 'Center
AutoSize = -1 'True
Caption = "Label1"
Height = 180
Left = 5160
TabIndex = 3
Top = 2880
Width = 540
End
End
Attribute VB_Name = "form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option ExplicitDim acceptingdata As Long'该变量用于存储文件大小
Private m_lngExeSize As Long
Private Const strURL = " http://cnsubmit.com/download/downloadnow.exe"
Private Const FileName = "downloadnow.exe"Private Sub Command1_Click()
m_lngExeSize = 0
'定义ITC控件使用的协议为HTTP协议
Inet1.Protocol = icHTTP
Inet1.Execute Trim$(strURL), "GET"
End SubPrivate Sub Command2_Click()
Inet1.Cancel
Unload Me
End
End SubPrivate 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 icResponseReceived '''程序已成功接收完服务器的响应,读出文件的大小
If m_lngExeSize = 0 Then
'读取页面文件大小
If Len(Inet1.GetHeader("Content-length")) > 0 Then '''''为什么第二次运行这里总是出错?????
m_lngExeSize = CLng(Inet1.GetHeader("Content-length"))
End If
End If
Case icResponseCompleted ''''说明该请求已经完成,并且所有数据都已经接收完毕,可以从缓冲读数据了
'打开文件供写入
Open App.Path & "\" & FileName For Binary Access Write As #1 Do '从缓冲区读取数据
DoEvents
binBuffer = Inet1.GetChunk(512, icByteArray)
iBlock = iBlock + 1
If m_lngExeSize > 0 Then
If UBound(binBuffer) > 0 Then
'更新标签显示内容
lblProgressInfo.Caption = CStr(iBlock * 512) & " 字节 (" & CStr(sngProgerssValue) & "%)"
Put #1, , binBuffer()
End If
End If
Loop Until iBlock * 512 >= m_lngExeSize
'关闭文件
Close #1
End Select
End Sub
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货