求助VB 读写文件!!
发布网友
发布时间:2024-09-27 17:06
我来回答
共4个回答
热心网友
时间:2024-11-29 02:22
'textbox的index从0开始
Private Sub Command1_Click()
Dim i As Integer, fname As String
fname = "d:\t.txt"
Open fname For Input As #1
Do While Not EOF(1)
Line Input #1, tmpstr
Text1(i) = tmpstr
i = i + 1
If i > 29 Then MsgBox "文本框不够了!": Exit Do
Loop
Close #1
End Sub
热心网友
时间:2024-11-29 02:22
Dim FileLines As Long '文件行数&textbox's index
Dim FileData As String '每行数据
Dim TFile As String '文件路径
TFile = "D:\a.txt"
Open TFile For Input As #1
If LOF(1) < 1 Then
Close
MsgBox "文件为空!", vbOKOnly, "提示!"
Exit Sub '退出过程
End If
Do While Not EOF(1) '循环到文件尾
Line Input #1, FileData '读入一行
If FileLines < 30 Then 'textbox控件数组只有30个元素
Text1(FileLines) = FileData '读入的数据赋值到textbox
End If
FileLines = FileLines + 1 '下一个textbox
Loop
Close
热心网友
时间:2024-11-29 02:23
为什么不用一个textbox?设置为多行?
设置Text1.MultiLine为True
Text1.ScrollBars 为3
代码:
Text1.Text = ""
Open "file.txt" For Input As 1
Do While Not EOF(1)
Input #1, a
Text1.Text = Text1.Text & a & vbCrLf
Loop
Close #1
热心网友
时间:2024-11-29 02:23
dim i as integer
dim TempStr() as string
open filename for input as #1
do while not eof(1)
i=i+1
redim preserve tempstr(i)
line input #1,tempstr(i)
text1(i).text=tempstr(i)
loop
close #1