怎么一句句用streamreader 读txt 为什么我是一起读出来的
Dimi%Dimtitle(20)AsStringDimaAsStringDimsrAsNewSystem.IO.StreamReader(Application.Sta...
Dim i%
Dim title(20) As String
Dim a As String
Dim sr As New System.IO.StreamReader(Application.StartupPath & "\tj.txt", System.Text.Encoding.Default)
Dim input As String
input = sr.ReadLine()
For i = 0 To 18
If Not input Is Nothing And i <= 18 Then
title(i) = Trim(input)
input = sr.ReadLine()
a = title(i)
End If
Label1.Text &= vbCrLf & a
Next
sr.Close() 展开
Dim title(20) As String
Dim a As String
Dim sr As New System.IO.StreamReader(Application.StartupPath & "\tj.txt", System.Text.Encoding.Default)
Dim input As String
input = sr.ReadLine()
For i = 0 To 18
If Not input Is Nothing And i <= 18 Then
title(i) = Trim(input)
input = sr.ReadLine()
a = title(i)
End If
Label1.Text &= vbCrLf & a
Next
sr.Close() 展开
1个回答
展开全部
你的程序是一次性执行完成的,当然全部读完
你想点一下按钮读一行,代码要在ReadLine后面中断
你想点一下按钮读一行,代码要在ReadLine后面中断
更多追问追答
追问
我用了一个timer
那要怎么修改才行呢
想让它一句句读完一个txt
追答
简单一点,就是做一个全局变量,记录当前读第几行
在你的例子里,就是把i放到外面成为全局变量
如:
在方法外面:Dim i as int
在方法里面:
Dim title(20) As String
Dim a As String
Dim sr As New System.IO.StreamReader(Application.StartupPath & "\tj.txt", System.Text.Encoding.Default)
Dim input As String
input = sr.ReadLine()
For j = 0 To i
If Not input Is Nothing And i <= 18 Then
title(i) = Trim(input)
input = sr.ReadLine()
a = title(i)
End If
Next
Label1.Text &= vbCrLf & a
sr.Close()
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询