问一个VB编程问题,关于读取txt文件的,希望高手帮忙解答下

2024-12-18 01:50:55
推荐回答(4个)
回答1:

建议用text控件组! 比如 TEXT1(0) TEXT1(1) ......
open "c:\1.txt" for input as #1
do while not eof(1)
line input #1,s
text1(i).text=s
i = i +1
loop
close #1

回答2:

自己翻书

回答3:

Private Sub Form_Load()
Dim I As Integer, N As Integer, St As String
Dim A() As String
Open App.Path + "\fb.dat" For Input As #1
Do While Not EOF(1)
Input #1, St
N = N + 1
Loop
Close #1
ReDim A(N)
I = 1
Open App.Path + "\fb.dat" For Input As #1
Do While Not EOF(1)
Input #1, A(I)
I = I + 1
Loop
Close #1
Text1(0).Visible = False
For I = 1 To N
Load Text1(I)
Text1(I).Top = (I - 1) * 500
Text1(I).Visible = True
Text1(I).Text = A(I)
Next
End Sub

回答4:

定义数组,定义对象变量
dim text(n) as textbox'不同的text控件
dim str(n) as string'每一行的文本字符
逐行读取到变量str(n) ,代码一搜一大把,根据需要增加变量
做个循环,循环赋值给textbox控件text(n)