目录

# Eof 函数

确定文件指针是否到达文件结尾。

### 语法:

    Eof (intexpression As Integer)

### Return type:

布尔

### 参数:

「Intexpression」: 用于计算打开文件的编号的任意整数表达式。

使用 EOF 函数，可以避免在输入时超过文件结尾的错误。当您使用 Input 或 Get 语句读取文件时，文件指针按照所读取的字节数向前移动。到达文件结尾时，EOF 返回 "True" (-1)。

### 错误代码:

5 无效的过程调用

52 错误的文件名或编号

### 示例:

      Sub ExampleWorkWithAFile
          Dim iNumber As Integer
          Dim sLine As String
          Dim aFile As String
          Dim sMsg As String
          aFile = "C:\Users\ThisUser\data.txt"
          iNumber = Freefile
          Open aFile For Output As #iNumber
          Print #iNumber, "This is a line of text"
          Print #iNumber, "This is another line of text"
          Close #iNumber
          iNumber = Freefile
          Open aFile For Input As iNumber
          While Not eof(iNumber)
              Line Input #iNumber, sLine
              If sLine <>"" Then
                  sMsg = sMsg & sLine & chr(13)
              End If
          Wend
          Close #iNumber
          MsgBox sMsg
      End Sub

      Sub ExampleWorkWithAFile
          Dim iNumber As Integer
          Dim sLine As String
          Dim aFile As String
          Dim sMsg As String
          aFile = "~/data.txt"
          iNumber = Freefile
          Open aFile For Output As #iNumber
          Print #iNumber, "This is a line of text"
          Print #iNumber, "This is another line of text"
          Close #iNumber
          iNumber = Freefile
          Open aFile For Input As iNumber
          While Not eof(iNumber)
              Line Input #iNumber, sLine
              If sLine <>"" Then
                  sMsg = sMsg & sLine & chr(13)
              End If
          Wend
          Close #iNumber
          MsgBox sMsg
      End Sub

相关主题

Close Statement

Print# Statement

Input# Statement

Open Statement

请支持我们!