我有一个文本文件,里边有50行不一样长的文本. 我想把这50行文本,读入50个txtbox 文本框里边,请问怎样做效率最高?示例:
文本内容:
i am ok
i am not ok
i am fine
........文件读进来完成的时候,我想在text1文本框里看到 i am ok
在text2文本框里看到 i am not ok
在text3文本框里看到 i am fine
........
文本内容:
i am ok
i am not ok
i am fine
........文件读进来完成的时候,我想在text1文本框里看到 i am ok
在text2文本框里看到 i am not ok
在text3文本框里看到 i am fine
........
Open "DDDD.txt" For Input As #1
Line Input #1, a2
Text2.text = a2
Line Input #1, a3
Text3.text = a3
Line Input #1, a4
Text4.text = a4
Line Input #1, a5
Text5.text = a5
......
Close #1就是不想这样用才问的啊,有没有别的方法呢?
这种方法对付几行句子还行,假有有1000行,我的手不要酸死了...
do while not eof(1)
Line Input #1, strTmp
txtTmp(i).text=strTmp
i=i+1
loop
txtTmp(i).text=strTmp 这句运行时老显示"子程序或函数未定义"
是不是text(i).text 中的i不能这样用,还是咋的.我一直觉得理论上应该是可以的,可是调试不出来啊.请指教
Dim i
i = 1
Dim strTmp
Open "dddd.text" For Input As #1Do While Not EOF(1)
Line Input #1, strTmp
Text(i).Text = strTmp
i = i + 1
LoopClose #1End Sub显示"子程序或函数未定义"
如果不是控件数组,名称只是text1,text2.....这样,那么修改为:
me.controls("text"& i).text=strTmp
你需要自己画控件数组亚!看样子你还是用2楼的方法比较的好
do while not eof(1)
Line Input #1, strTmp
if i>0 then load txtTmp(i)
txtTmp(i).text=strTmp
i=i+1
loop
在建表時,把text控制,复制几個就出來,控制項陣列
对于大的数据,用表格代替text来显示效率会比较高
还50行不一样长的数据,都知道它是一行一行的
了,用陈辉的方法就可以了,学会使用控件数组
是件好事。
Dim a() As StringOpen "c:\DDDD.txt" For Input As #1
Do Until EOF(1)
Line Input #1, strLine
ReDim Preserve a(i)
a(i) = strLine
i = i + 1
Loop
Close #1
For Each x In Me.Controls
If Left(x.Name, 4) = "Text" Then
x.Text = a(Val(Mid(x.Name, 5)) - 1)
End If
Next x