VB读取网上的TXT文本文档到Text1里,怎末实现?

我实在没一分了,那位高手帮帮我,感激不尽啊!!
只是这一个功能,只是读取,没别的了。。。。。。。。。

这是我用vb.net写 完全可以调用
Public Sub readtxt()
'Dim path As String = "\Storage Card\Scr.txt"
Dim mystr As String
Dim Num As Integer

OpenFileDialog1.ShowDialog() ‘这个选择的路径的控件,需在你的项目上添加
Dim aa As String = OpenFileDialog1.FileName
Try
Dim sr As StreamReader = New StreamReader(aa, System.Text.Encoding.Default)
sr.BaseStream.Seek(0, SeekOrigin.Begin)
Do While sr.Peek() > 0
mystr = sr.ReadLine
textbox1.Text = mystr '此时的mystr是一行一行的读取
ElseIf mystr = "" Then
GoTo endloop
End If
endloop:
Loop
sr.Close()
Catch Ee As Exception
Console.WriteLine("The file could not be read:")
Console.WriteLine(Ee.Message)
End Try
End Sub
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-07-06
假设你这文本文件是在:D:\AA\XX.TXT
OPEN "" FOR INPUT AS #1
WHILE (NOT EOF(1)) ;一直读到文件结束为止
LINEINPUT #1,A ;从该文件中读出一行
TEXT1.TEXT=A ;读出的文本送到TEXT1中,复盖TEXT1原来的内容
LOOP
CLOSE #1本回答被网友采纳
第2个回答  2012-07-07
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

sub cmmand1_click()‘例如网上为1.txt
R= URLDownloadToFile(0,"http://www.abc.com/1.txt" , "c:\1.txt", 0, 0)
open “c:\1.txt" for input as #1
do until eof(1)
line input #1,a
text1=text1 & a & vbcrlf
loop
close
end sub
相似回答