你循环错了
你用for好了
改成
Open "d:\vb\stulnfo.dat" For Input As #1
ReDim myArray(LOF(1))
For i = 1 To 4
Line Input #1, myArray(i)
Next i
Close #1
For i = 1 To 4
Print myArray(i)
Next i
如果你要添加记录什么的不只4条的话,就就在第一行写下总共的行数再读取第一行为末尾条数就可以了
Input #1, myArray(i)
这一句中的i没有意义。
i值恒为0,而你最后读出的是1至10,显然出现空值。
给两个通用函数你
自己看着用
你自己试试
msgbox openfile("读入文件的绝对路径")
Public Function openfile(ByVal filepath As String) As String
Dim s As String
Open filepath For Input As #1
While Not EOF(1)
Line Input #1, sline
s = s & sline & vbCrLf
Wend
Close #1
openfile = s
End Function
Public Function savefile(ByVal filepath As String, ByVal txt As String)
Open filepath For Output As #1
Print #1, txt
Close #1
End Function
Function disStr(ByVal vstr As String) As String '文件路径/\字符处理函数
If Right$(vstr, 1) <> "\" And Right$(vstr, 1) <> "/" And vstr <> "" Then
disStr = vstr & "\"
Else
disStr = vstr
End If
End Function