vb程序提示“输入超出文件尾”

Option Base 1
Private Sub C1_Click()
Dim a(100) As Integer
Dim s As Integer
s = 0

Open App.Path & "\" & "in.txt" For Input As #1
Do While Not EOF(1)
For i = 1 To 100
Input #1, a(i)
Text1.Text = Text1.Text & " " & a(i)

If a(i) <= 700 Then
s = s + a(i)
End If
Next
Loop
Close #1

End Sub

in.txt 文件内容如下:

705 533 579 289 301 774 14 760 814 709 45 414 862 790 373 961 871 56 949 364
524 767 53 592 468 298 622 647 263 279 829 824 589 986 910 226 695 980 243 533
106 999 676 15 575 100 103 798 284 45 295 382 300 948 979 401 278 160 162 646
410 412 712 326 633 207 186 583 80 457 905 261 785 378 289 919 631 627 428 97
561 694 913 834 22 543 916 430 677 502 513 462 353 404 269 55 243 979 60 390

请问到底哪里出了问题,以及怎样改进?

第1个回答  2012-03-24
Option Base 1
Private Sub C1_Click()
Dim a(100) As Integer
Dim s As Integer
s = 0
Open App.Path & "\" & "in.txt" For Input As #1
For i = 1 To 100
Input #1, a(i)
If EOF(1) Then Exit For
Text1.Text = Text1.Text & " " & a(i)
If a(i) <= 700 Then
s = s + a(i)
End If
Next
Close #1
End Sub
第2个回答  2012-03-24
修改后:
Option Base 1
Private Sub C1_Click()
Dim a(100) As Integer
Dim s As Integer
s = 0

Open App.Path & "\" & "in.txt" For Input As #1
Do While Not EOF(1)
For i = 1 To 100
If EOF(1) Then Close #1:Exit For
Input #1, a(i)
Text1.Text = Text1.Text & " " & a(i)

If a(i) <= 700 Then
s = s + a(i)
End If
Next
Loop
Close #1

End Sub本回答被网友采纳
第3个回答  2012-03-24
复制代码运行了一下,没有"输入超出文件尾"提示
第4个回答  2012-03-24
Open App.Path & "\" & "in.txt" For appand As #1
相似回答