Share via


LOF 函式

更新:2007 年 11 月

傳回 Long,表示用 FileOpen 函式所開啟檔案的大小 (以位元組為單位)。

My 功能在檔案 I/O 作業中的產能和效能勝過 LOF。如需詳細資訊,請參閱 My.Computer.FileSystem 物件

Public Function LOF(ByVal FileNumber As Integer) As Long

參數

  • FileNumber
    必要項。包含有效檔案數目的 Integer。

例外狀況

例外狀況類型

錯誤代碼

條件

IOException

52

FileNumber 不存在。

IOException

54

檔案模式無效。

如果將使用非結構化錯誤處理的 Visual Basic 6.0 應用程式升級,請參閱「錯誤代碼」資料行 (您可以將錯誤代碼與 Number 屬性 (Err 物件) 比對)。但是,請盡可能考慮以 Visual Basic 的結構化例外處理概觀 取代這類錯誤控制項。

備註

使用 FileLen 函式取得未開啟檔案的長度。

範例

這個範例使用 LOF 函式判斷開啟檔案的大小。這個範例會假設 TestFile 為內含範例資料的文字檔。

Dim length As Long
FileOpen(1, "C:\TESTFILE.TXT", OpenMode.Input) ' Open file.
length = LOF(1)   ' Get length of file.
MsgBox(length)
FileClose(1)   ' Close file.

智慧型裝置開發人員注意事項

不支援這個函式。

需求

命名空間 (Namespace)︰Microsoft.VisualBasic

**模組︰**FileSystem

組件:Visual Basic Runtime Library (在 Microsoft.VisualBasic.dll 中)

請參閱

參考

EOF 函式

FileLen 函式

Loc 函式

FileOpen 函式

IOException

其他資源

在 Visual Basic 中讀取檔案

在 Visual Basic 中寫入檔案