到底如何用vb6读取网站上的txt文件???

来源:百度知道 编辑:UC知道 时间:2024/05/16 10:19:22
我在网站找了好多年。。。。
都运行不了,只有这一个,能运行,不提示错误,但是却不执行DownloadFile操作。
请师父给个说法。
代码如下:
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, LocalFilename As String) As Boolean
Dim lngRetVal As Long
lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
If lngRetVal = 0 Then DownloadFile = True
End Function

Private Sub Command1_Click()
Dim l as string
DownloadFile "http://www.ta2shou.com/a.txt","d:\a.txt" '下载文件
Open "d:\a.txt" For Input As #1 '读取文件
Do Until Eof(1)
Line Input #1, l '一行一行读取
Text1.Text = Text1.Text & vbcrlf & l '写入到text1里面

"","baidu","www.baidu.com"
我读到这些。。。你却不能??

用xmlhttp比较简单:
Sub test()
Dim xmlhttp, sText As String
Set xmlhttp = CreateObject("Microsoft.XMLHTTP")
With xmlhttp
.Open "Get", "http://www.ta2shou.com/a.txt", False
.Send
Text1.Text = .Responsetext
End With
End Sub