vb如何打开1000个txt文件 然后按下按钮按照顺序逐行显示在text1中
我有1000个txt文件,分别为1.txt2.txt3.txt------1000.txt每个文本都很多行,按下command1将这些文件线加载到内存中按下command...
我有1000个txt文件,分别为1.txt 2.txt 3.txt------1000.txt
每个文本都很多行,按下command1 将这些文件线加载到内存中 按下command2 将这些文件通过timer1按照顺序每个显示一遍(要逐行,每个txt显示是都要清空一次) 展开
每个文本都很多行,按下command1 将这些文件线加载到内存中 按下command2 将这些文件通过timer1按照顺序每个显示一遍(要逐行,每个txt显示是都要清空一次) 展开
展开全部
加载到内存这一步就没必要了,这样做并不会比直接读取文件并立刻显示快,而且一次性读取这么多数据到内存,很容易造成系统崩溃。
Private Sub Command2_Click()
Timer1.Interval = 500
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Static o As Boolean, f As Long
Dim s As String, t As String
If Not o Then
Close
f = f + 1
t = App.Path & "\" & f & ".txt"
If f > 1000 Then
Timer1.Enabled = False
MsgBox "全部读取完毕!"
f = 0
Exit Sub
ElseIf Dir(t) = "" Then
If MsgBox(t & "未找到!要退出吗?", vbOKCancel) = vbOK Then Timer1.Enabled = False
Exit Sub
End If
Open t For Input As #1
Text1.Text = ""
End If
Line Input #1, s
Text1.Text = Text1.Text & s & vbCrLf
o = EOF(1)
End Sub
Private Sub Command2_Click()
Timer1.Interval = 500
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Static o As Boolean, f As Long
Dim s As String, t As String
If Not o Then
Close
f = f + 1
t = App.Path & "\" & f & ".txt"
If f > 1000 Then
Timer1.Enabled = False
MsgBox "全部读取完毕!"
f = 0
Exit Sub
ElseIf Dir(t) = "" Then
If MsgBox(t & "未找到!要退出吗?", vbOKCancel) = vbOK Then Timer1.Enabled = False
Exit Sub
End If
Open t For Input As #1
Text1.Text = ""
End If
Line Input #1, s
Text1.Text = Text1.Text & s & vbCrLf
o = EOF(1)
End Sub
展开全部
'假设你的内容是在Text1显示
dim s as string
private sub command1_click()
for i=1 to 1000
open app.path & "\" & cstr(i) & ".txt" for input as #i
next i
end sub 'Command1_click 打开1000个文件
private sub command2_click()
Timer1.Enabled=True
for i=1 to 1000
do while not eof(i)
lineinput i,s
loop
next i
end sub 'Command2设置Timer1计时器有效
private sub timer1_timer()
text1.text=""
text1.text=s
end sub
dim s as string
private sub command1_click()
for i=1 to 1000
open app.path & "\" & cstr(i) & ".txt" for input as #i
next i
end sub 'Command1_click 打开1000个文件
private sub command2_click()
Timer1.Enabled=True
for i=1 to 1000
do while not eof(i)
lineinput i,s
loop
next i
end sub 'Command2设置Timer1计时器有效
private sub timer1_timer()
text1.text=""
text1.text=s
end sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询