vb读取网站目录txt文件内容到text1.text

比如读取www.baidu.com/wen.txt内的内容到text1.text

API:

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.baidu.com/wen.txt","C:\tmp.txt" '下载文件
Open "C:\tmp.txt" For Input As #1 '读取文件
Do Until Eof(1)
Line Input #1, l '一行一行读取
Text1.Text = Text1.Text & vbcrlf & l '写入到text1里面
Loop
Close #1
Kill "C:\tmp.txt" '删除临时文件
End Sub
温馨提示:答案为网友推荐,仅供参考
相似回答