VB下载网上文件代码(有进度条显示)

本栏文章均来自于互联网,版权归原作者和各发布网站所有,收集这些文章仅供学习参考之用。任何人都不能将这些文章用于商业或者其他目的。 '添加 internet transfer control 6.0 和 windows commom controls 6.0 'form代码: Private Sub cmdGET_Click() StartDownLoad txtURL End Sub Private Sub Form_Load() savefile.Text = App.Path End Sub Private Sub StartDownLoad(ByVal Geturl As String) 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 Inet1.Execute Geturl, "get" '开始下载 End Sub Private Sub Inet1_StateChanged(ByVal State As Integer) 'State = 12 时,用 GetChunk 方法检索服务器的响应。 Dim vtData() As Byte Select Case State '...没有列举其它情况。 Case icError '11 '出现错误时,返回 ResponseCode 和 ResponseInfo。 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 Close #1 MsgBox "下载完成", vbInformation, "通知" End Select End Sub[@more@]

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/8383357/viewspace-919735/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/8383357/viewspace-919735/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值