
VB代码求教。下载网络上指定文件
我需要一个一段代码,下载网络上指定文件,保存到本地指定目录下。我已经写了网址部分的代码,可以生成一系列网络文件地址URl,现在我需要知道怎么写“下载”这个功能的代码。...
我需要一个一段代码,下载网络上指定文件,保存到本地指定目录下。我已经写了网址部分的代码,可以生成一系列网络文件地址URl,现在我需要知道怎么写“下载”这个功能的代码。
展开
展开全部
下面的代码可以下载百度的LOGO,下载后的文件是c:\baidu.gif
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Public Function DownloadFile(URL As String, fn As String) As Boolean
DownloadFile = (URLDownloadToFile(0, URL, fn, 0, 0) = 0)
End Function
Private Sub Command1_Click()
If DownloadFile("http://www.baidu.com/img/shouye_b5486898c692066bd2cbaeda86d74448.gif", "c:\baidu.gif") Then
MsgBox "下载成功!"
Else
MsgBox "下载失败!"
End If
End Sub
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Public Function DownloadFile(URL As String, fn As String) As Boolean
DownloadFile = (URLDownloadToFile(0, URL, fn, 0, 0) = 0)
End Function
Private Sub Command1_Click()
If DownloadFile("http://www.baidu.com/img/shouye_b5486898c692066bd2cbaeda86d74448.gif", "c:\baidu.gif") Then
MsgBox "下载成功!"
Else
MsgBox "下载失败!"
End If
End Sub

2024-09-19 广告
随着AI技术的飞速发展,如今市面上涌现了许多实用易操作的AI生成工具1、简介:AiPPT: 这款AI工具智能理解用户输入的主题,提供“AI智能生成”和“导入本地大纲”的选项,生成的PPT内容丰富多样,可自由编辑和添加元素,图表类型包括柱状图...
点击进入详情页
本回答由AiPPT提供
展开全部
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Private Sub Command1_Click()
a = URLDownloadToFile(0, "http://www.51dangao.com/Amepic/2012111917292571451.jpg", App.Path & "\123.jpg", 0, 0)
If a = 0 Then
MsgBox "下载完毕"
End If
End Sub
Private Sub Command1_Click()
a = URLDownloadToFile(0, "http://www.51dangao.com/Amepic/2012111917292571451.jpg", App.Path & "\123.jpg", 0, 0)
If a = 0 Then
MsgBox "下载完毕"
End If
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询