代码一:
Private Sub Form_Load()
Dim 数组() As String '定义一个动态数组
Dim i As Integer
Open "C:\Users\Admin\Desktop\1.txt" For Input As 1#
'打开输入文件
Do While Not EOF(1)
ReDim Preserve 数组(i)
'分配数组,保留原来的数据
Line Input #1, 数组(i)
'读入数据
i = i + 1
Loop
For i = 0 To UBound(数组)
Debug.Print 数组(i)
Next
Debug.Print
Debug.Print 数组(0)
Close #1
'关闭文件
End Sub
代码二:
Private Sub Form_Load()
Dim data As String
Dim buffer As String
Dim str As String
Open "1.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, buffer
data = data + buffer + vbCrLf
Loop
'MsgBox data
Close #1
S = Split(data, Chr(13) & Chr(10))
'以回车换行符作为分隔符
For i = 0 To UBound(S)
MsgBox S(i)
Next
End Sub
代码三:
Private Sub Form_Load()
Dim data As String
Dim buffer As String
Dim str As String
Open "1.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, buffer
data = data + buffer + vbCrLf
Loop
'MsgBox data
Close #1
str = Replace(data, Chr(13) & Chr(10), ",") '回车换行符全部替换成逗号
S = Split(str, ",") '以逗号作为分隔符
For i = 0 To UBound(S)
MsgBox S(i)
Next
End Sub