EOF 関数 vb.net入門


EOF 関数はファイルの末尾を取得します。

末尾だとTrue を返します。

構文
EOF(ファイルナンバー)

ソース

Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim str As String = Nothing
FileOpen(1, “C:\Users\user\Desktop\hoge.txt”, OpenMode.Input)
While Not EOF(1)
Input(1, Str)
MsgBox(Str)
End While

If EOF(1) Then
MsgBox(”末尾だよ”)
End If
FileClose()
End Sub

End Class

実行結果は
全てのデータをループで取得します。
if文で末尾を取得します。

if文で書いた式をループで書くと無限ループになります。

ソース2
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim str As String = Nothing
FileOpen(1, “C:\Users\user\Desktop\hoge.txt”, OpenMode.Binary)
While Not EOF(1)
Input(1, str)
MsgBox(str)
End While

If EOF(1) Then
MsgBox(”末尾だよ”)
End If
FileClose()
End Sub

End Class

実行結果は
同じです。

シェアする

  • このエントリーをはてなブックマークに追加

フォローする

Translate »