'我写的一个例子,用Internet Transfor Control下载
VERSION 5.00
Object = "{48E59290-9880-11CF-9754-00AA00C00908}#1.0#0"; "MSINET.OCX"
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3480
ClientLeft = 60
ClientTop = 345
ClientWidth = 5745
LinkTopic = "Form1"
ScaleHeight = 3480
ScaleWidth = 5745
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox Text2
Height = 405
Left = 900
TabIndex = 6
Text = "C:\media2db.zip"
Top = 630
Width = 4665
End
Begin VB.PictureBox Picture1
Appearance = 0 'Flat
BackColor = &H80000001&
ForeColor = &H80000008&
Height = 405
Left = 150
ScaleHeight = 375
ScaleWidth = 0
TabIndex = 4
Top = 1350
Visible = 0 'False
Width = 15
End
Begin VB.CommandButton Command2
Caption = "有时度条下载"
Height = 525
Left = 3270
TabIndex = 2
Top = 2850
Width = 1335
End
Begin VB.TextBox Text1
Height = 375
Left = 900
TabIndex = 1
Text = "http://www14.brinkster.com/weblover/media2db.zip"
Top = 150
Width = 4665
End
Begin VB.CommandButton Command1
Caption = "无进度条下载"
Height = 525
Left = 1440
TabIndex = 0
Top = 2850
Width = 1365
End
Begin InetCtlsObjects.Inet Inet1
Left = 510
Top = 2760
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
End
Begin VB.Label Label4
Caption = "SaveAs"
Height = 345
Left = 120
TabIndex = 8
Top = 660
Width = 615
End
Begin VB.Label Label3
Caption = "URL"
Height = 345
Left = 120
TabIndex = 7
Top = 180
Width = 615
End
Begin VB.Label Label2
Caption = "Label2"
Height = 345
Left = 1980
TabIndex = 5
Top = 1860
Width = 1335
End
Begin VB.Label Label1
Caption = "Label1"
Height = 345
Left = 480
TabIndex = 3
Top = 2280
Width = 4725
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim LastTextBox As TextBoxDim TotalLength As Long
Dim Step As SinglePrivate Sub Command1_Click()
Dim File() As Byte
File() = Inet1.OpenURL(Text1.Text, icByteArray)
Open Text2.Text For Binary Access Write As #1
Put #1, , File()
Close #1
MsgBox "Success"
End SubPrivate Sub Command2_Click()
Inet1.Execute Text1.Text, "GET"
End SubPrivate Sub Form_Load()
Text1.Text = "http://www14.brinkster.com/weblover/media2db.zip"
End SubPrivate Sub Inet1_StateChanged(ByVal State As Integer)
On Error GoTo Errhandler
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 Text2.Text For Binary Access Write As #1
vtData = Inet1.GetChunk(1024, icByteArray)
Count = 1000
Picture1.Width = Picture1.Width + Count * Step
Picture1.Visible = True
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
Exit Sub
Errhandler:
MsgBox Err.Description
End Sub
VERSION 5.00
Object = "{48E59290-9880-11CF-9754-00AA00C00908}#1.0#0"; "MSINET.OCX"
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3480
ClientLeft = 60
ClientTop = 345
ClientWidth = 5745
LinkTopic = "Form1"
ScaleHeight = 3480
ScaleWidth = 5745
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox Text2
Height = 405
Left = 900
TabIndex = 6
Text = "C:\media2db.zip"
Top = 630
Width = 4665
End
Begin VB.PictureBox Picture1
Appearance = 0 'Flat
BackColor = &H80000001&
ForeColor = &H80000008&
Height = 405
Left = 150
ScaleHeight = 375
ScaleWidth = 0
TabIndex = 4
Top = 1350
Visible = 0 'False
Width = 15
End
Begin VB.CommandButton Command2
Caption = "有时度条下载"
Height = 525
Left = 3270
TabIndex = 2
Top = 2850
Width = 1335
End
Begin VB.TextBox Text1
Height = 375
Left = 900
TabIndex = 1
Text = "http://www14.brinkster.com/weblover/media2db.zip"
Top = 150
Width = 4665
End
Begin VB.CommandButton Command1
Caption = "无进度条下载"
Height = 525
Left = 1440
TabIndex = 0
Top = 2850
Width = 1365
End
Begin InetCtlsObjects.Inet Inet1
Left = 510
Top = 2760
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
End
Begin VB.Label Label4
Caption = "SaveAs"
Height = 345
Left = 120
TabIndex = 8
Top = 660
Width = 615
End
Begin VB.Label Label3
Caption = "URL"
Height = 345
Left = 120
TabIndex = 7
Top = 180
Width = 615
End
Begin VB.Label Label2
Caption = "Label2"
Height = 345
Left = 1980
TabIndex = 5
Top = 1860
Width = 1335
End
Begin VB.Label Label1
Caption = "Label1"
Height = 345
Left = 480
TabIndex = 3
Top = 2280
Width = 4725
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim LastTextBox As TextBoxDim TotalLength As Long
Dim Step As SinglePrivate Sub Command1_Click()
Dim File() As Byte
File() = Inet1.OpenURL(Text1.Text, icByteArray)
Open Text2.Text For Binary Access Write As #1
Put #1, , File()
Close #1
MsgBox "Success"
End SubPrivate Sub Command2_Click()
Inet1.Execute Text1.Text, "GET"
End SubPrivate Sub Form_Load()
Text1.Text = "http://www14.brinkster.com/weblover/media2db.zip"
End SubPrivate Sub Inet1_StateChanged(ByVal State As Integer)
On Error GoTo Errhandler
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 Text2.Text For Binary Access Write As #1
vtData = Inet1.GetChunk(1024, icByteArray)
Count = 1000
Picture1.Width = Picture1.Width + Count * Step
Picture1.Visible = True
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
Exit Sub
Errhandler:
MsgBox Err.Description
End Sub
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货