Private Sub Command2_Click()
'Dim Downlist As String
Downlist = "http://www.1.com/down/1.gif|http://www.1.com/images/2.gif|http://www.1.com/images/3.gif"
Lista = Split(Downlist, "|")
Lists = UBound(Lista)
For i = 0 To Lists
StartDownLoad Lista(i)
Next
End SubPrivate Sub StartDownLoad(ByVal Geturl As String)
If Inet1.StillExecuting Then Exit Sub
Dim spo%, filename$
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FolderExists(App.Path & "\download") Then Set f = fso.CreateFolder(App.Path & "\download")
spo = InStrRev(Geturl, "/")
filename = Right(Geturl, Len(Geturl) - spo) '获取文件名
savefile.Text = App.Path & "\download\" & filename
Label7.Caption = filename
Inet1.Execute Geturl, "get" '开始下载
End SubPrivate Sub Inet1_StateChanged(ByVal State As Integer)
'State = 12 时,用 GetChunk 方法检索服务器的响应。
Dim vtData() As Byte
Select Case State
'...没有列举其它情况。
Case icError '11
'出现错误时,返回 ResponseCode 和 ResponseInfo。
MsgBox "连接服务器失败!", 64
Exit Sub
vtData = Inet1.ResponseCode & ":" & Inet1.ResponseInfo
Case icResponseCompleted ' 12
Dim bDone As Boolean: bDone = False
'取得第一个块。
vtData() = Inet1.GetChunk(1024, 1)
DoEvents
Open savefile.Text For Binary Access Write As #1 '设置保存路径文件后开始保存
'获取下载文件长度
If Len(Inet1.GetHeader("Content-Length")) > 0 Then ProgressBar1.Max = CLng(Inet1.GetHeader("Content-Length"))
'循环分块下载
Do While Not bDone
Put #1, Loc(1) + 1, vtData()
vtData() = Inet1.GetChunk(1024, 1)
DoEvents
ProgressBar1.Value = Loc(1) '设置进度条长度
If Loc(1) >= ProgressBar1.Max Then bDone = True
Loop
Inet1.Cancel
Close #1
MsgBox "下载所有文件成功", vbInformation, "完成"
End Select
End Sub只下载了第一个文件就不执行了好像,如果循环下载多个文件,请高手们指点一下谢谢
'Dim Downlist As String
Downlist = "http://www.1.com/down/1.gif|http://www.1.com/images/2.gif|http://www.1.com/images/3.gif"
Lista = Split(Downlist, "|")
Lists = UBound(Lista)
For i = 0 To Lists
StartDownLoad Lista(i)
Next
End SubPrivate Sub StartDownLoad(ByVal Geturl As String)
If Inet1.StillExecuting Then Exit Sub
Dim spo%, filename$
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FolderExists(App.Path & "\download") Then Set f = fso.CreateFolder(App.Path & "\download")
spo = InStrRev(Geturl, "/")
filename = Right(Geturl, Len(Geturl) - spo) '获取文件名
savefile.Text = App.Path & "\download\" & filename
Label7.Caption = filename
Inet1.Execute Geturl, "get" '开始下载
End SubPrivate Sub Inet1_StateChanged(ByVal State As Integer)
'State = 12 时,用 GetChunk 方法检索服务器的响应。
Dim vtData() As Byte
Select Case State
'...没有列举其它情况。
Case icError '11
'出现错误时,返回 ResponseCode 和 ResponseInfo。
MsgBox "连接服务器失败!", 64
Exit Sub
vtData = Inet1.ResponseCode & ":" & Inet1.ResponseInfo
Case icResponseCompleted ' 12
Dim bDone As Boolean: bDone = False
'取得第一个块。
vtData() = Inet1.GetChunk(1024, 1)
DoEvents
Open savefile.Text For Binary Access Write As #1 '设置保存路径文件后开始保存
'获取下载文件长度
If Len(Inet1.GetHeader("Content-Length")) > 0 Then ProgressBar1.Max = CLng(Inet1.GetHeader("Content-Length"))
'循环分块下载
Do While Not bDone
Put #1, Loc(1) + 1, vtData()
vtData() = Inet1.GetChunk(1024, 1)
DoEvents
ProgressBar1.Value = Loc(1) '设置进度条长度
If Loc(1) >= ProgressBar1.Max Then bDone = True
Loop
Inet1.Cancel
Close #1
MsgBox "下载所有文件成功", vbInformation, "完成"
End Select
End Sub只下载了第一个文件就不执行了好像,如果循环下载多个文件,请高手们指点一下谢谢
解决方案 »
- 请问各位大虾:VB一般如何在一个窗体中实现列表后打开不同的页面进行修改的?
- XP遇到个麻烦的问题
- 总是出现438运行时错误,请帮我看一下下面这段excle宏代码,什么地方有问题
- 请教一个字符相加的小问题?在线等
- 为什么要等我command__Click执行完了,winsock才能更新服务器端的数据?
- 请问谁有写好的小写转大写程序?
- 高手救命!关于把SQL数据内容导出为XML文件问题
- 百分大奉送
- 98下打包,安装后在干净的98上可以运行,2000下不行。100分求助
- 如何在ado数据环境dataevironment中打开有密码的access表?
- VB实现文件的快速搜索问题
- 请问:VB中,如何获取主板的序列号?
变量是否赋值错误。If Inet1.StillExecuting Then Exit Sub
退出就不对了,应该等它结束。