Str是个函数的名字,在VB中属于保留字,尽量不要使用它作为变量的名称 dim i as Integer i=0 dim MyStr as String Open "C:\姓名.txt" For Input As #1 Do While Not EOF(1) Line Input #1, MyStr Text1(i).Text = MyStr i=i+1 Loop Close #1
检查一下文本文件里是不是多余8行,比如空白行 可以这样改 dim i as Integer i=0 dim MyStr as String Open "C:\姓名.txt" For Input As #1 Do While Not EOF(1) Line Input #1, MyStr Text1(i).Text = MyStr i=i+1 if i>=Text1.Count Then Exit Do Loop Close #1
dim I as longOpen "C:\姓名.txt" For Input As #1
If LOF(1) > 0 Then
While Not EOF(1)
x = DoEvents
Line Input #1, str
Text1(i).Text = str
i=i+1
Wend
End If
Close #1
另外还有一个复杂化的方法,你可以用数据库的方法,将文本中的内容读入数据库中,而窗体上的文本框与数据库字段绑定,这样就用不着向文本框写值了.
dim i as Integer
i=0
dim MyStr as String
Open "C:\姓名.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, MyStr
Text1(i).Text = MyStr
i=i+1
Loop
Close #1
实时错误340,控件组8不存在? 这里变黄了(Text1(i).Text = MyStr) 我现在(0)-----(7)个
可以这样改
dim i as Integer
i=0
dim MyStr as String
Open "C:\姓名.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, MyStr
Text1(i).Text = MyStr
i=i+1
if i>=Text1.Count Then Exit Do
Loop
Close #1