VB中自动从网站下载文件,知道的给20分

比如:自动从http://11.dc.ftn.qq.com/ftn_handler/176097eab6de3ce2bb0e87cee4908451137b6dcc98e11840fbeddb7198bdd30e4fa86f6984fc40d67d970856a9ac9a8077dd1f6c39a37a0ca6cdbccca63385cf/相册.rar?k=59663733a472d8c6ef0c511713380316005f5252535b085c490305015615050c05021a51025a041406560203035e075c07030106353031f684d4d61d4759433959&&txf_fid=749f5c06096077630949693871ac6f31db053ddc
上下载相册.rar到"upgrade\photo.rar"
代码该怎么写?
写错了。。。
当点击command1是,
自动从http://11.dc.ftn.qq.com/ftn_handler/176097eab6de3ce2bb0e87cee4908451137b6dcc98e11840fbeddb7198bdd30e4fa86f6984fc40d67d970856a9ac9a8077dd1f6c39a37a0ca6cdbccca63385cf/相册.rar?k=59663733a472d8c6ef0c511713380316005f5252535b085c490305015615050c05021a51025a041406560203035e075c07030106353031f684d4d61d4759433959&&txf_fid=749f5c06096077630949693871ac6f31db053ddc
上下载相册.rar到"upgrade\photo.rar"
代码该怎么写?

Option Explicit

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 Const ERROR_SUCCESS As Long = 0
Private Const BINDF_GETNEWESTVERSION As Long = &H10
Private Const INTERNET_FLAG_RELOAD As Long = &H80000000

Public Function DownloadFile(sSourceUrl As String, _
sLocalFile As String) As Boolean

DownloadFile = URLDownloadToFile(0&, _
sSourceUrl, _
sLocalFile, _
BINDF_GETNEWESTVERSION, _
0&) = ERROR_SUCCESS

End Function

Private Sub Command1_Click()
Dim sSourceUrl As String
Dim sLocalFile As String

sSourceUrl = "http://11.dc.ftn.qq.com/ftn_handler/176097eab6de3ce2bb0e87cee4908451137b6dcc98e11840fbeddb7198bdd30e4fa86f6984fc40d67d970856a9ac9a8077dd1f6c39a37a0ca6cdbccca63385cf/相册.rar?k=59663733a472d8c6ef0c511713380316005f5252535b085c490305015615050c05021a51025a041406560203035e075c07030106353031f684d4d61d4759433959&&txf_fid=749f5c06096077630949693871ac6f31db053ddc"
sLocalFile = "c:\相册.rar"

If DownloadFile(sSourceUrl, sLocalFile) Then

MsgBox "下载成功"
End If

End Sub

下载文件到 c:\相册.rar

路径自己改吧 sLocalFile 就是设置本地存放文件位置
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-05-08
学习下……
相似回答