VB读取网上的TXT文本文档到Text1里,怎末实现?
我实在没一分了,那位高手帮帮我,感激不尽啊!!只是这一个功能,只是读取,没别的了。。。。。。。。。...
我实在没一分了,那位高手帮帮我,感激不尽啊!!
只是这一个功能,只是读取,没别的了。。。。。。。。。 展开
只是这一个功能,只是读取,没别的了。。。。。。。。。 展开
3个回答
展开全部
这是我用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
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
展开全部
假设你这文本文件是在:D:\AA\XX.TXT
OPEN "" FOR INPUT AS #1
WHILE (NOT EOF(1)) ;一直读到文件结束为止
LINEINPUT #1,A ;从该文件中读出一行
TEXT1.TEXT=A ;读出的文本送到TEXT1中,复盖TEXT1原来的内容
LOOP
CLOSE #1
OPEN "" FOR INPUT AS #1
WHILE (NOT EOF(1)) ;一直读到文件结束为止
LINEINPUT #1,A ;从该文件中读出一行
TEXT1.TEXT=A ;读出的文本送到TEXT1中,复盖TEXT1原来的内容
LOOP
CLOSE #1
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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
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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询