EOF VBA 阻止我访问文件的最后一行
EOF VBA blocks me from accessing last line of my file
我正在尝试遍历一个文本文件。我对该文件的每一行进行了具体检查,以了解它是否会被粘贴。我正在使用以下代码。但是使用 EOF 阻止我访问最后一行,这有时很有用。
Dim buffer As String
Open file For Input As #1
Line Input #1, buffer
i = 1
j = 1
Do Until EOF(1) And i > coll(coll.Count)
If i = coll(j) Then
ListSplit = Split(buffer, ",") 'Split the line with "," delimiter
'...
j=j+1
End If
Line Input #1, buffer
i = i + 1
Loop
Close #1
像这样构建你的逻辑:
Open file For Input As #1
Do
Line Input #1, buffer
Debug.Print buffer 'do your work
Loop Until EOF(1)
Close #1
您发布的代码的问题是读取最后一行,设置 EOF,然后循环。评估条件并退出循环。
我正在尝试遍历一个文本文件。我对该文件的每一行进行了具体检查,以了解它是否会被粘贴。我正在使用以下代码。但是使用 EOF 阻止我访问最后一行,这有时很有用。
Dim buffer As String
Open file For Input As #1
Line Input #1, buffer
i = 1
j = 1
Do Until EOF(1) And i > coll(coll.Count)
If i = coll(j) Then
ListSplit = Split(buffer, ",") 'Split the line with "," delimiter
'...
j=j+1
End If
Line Input #1, buffer
i = i + 1
Loop
Close #1
像这样构建你的逻辑:
Open file For Input As #1
Do
Line Input #1, buffer
Debug.Print buffer 'do your work
Loop Until EOF(1)
Close #1
您发布的代码的问题是读取最后一行,设置 EOF,然后循环。评估条件并退出循环。