共用方式為


FreeFile 函式

更新:2007 年 11 月

傳回 Integer 值,表示 FileOpen 函式可以使用的下一個檔案編號。

Public Function FreeFile() As Integer

例外狀況

例外狀況類型

錯誤代碼

條件

IOException

67

使用中的檔案超過 255 個。

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

備註

使用 FreeFile 來提供未使用的檔案號碼。

範例

這個範例使用 FreeFile 函式傳回下一個可用的檔案號碼。迴圈中開啟了五個輸出用的檔案,並在每個檔案中寫入範例資料。

Dim count As Integer
Dim fileNumber As Integer
For count = 1 To 5   
   fileNumber = FreeFile()
   FileOpen(fileNumber, "TEST" & count & ".TXT", OpenMode.Output)
   PrintLine(fileNumber, "This is a sample.")
   FileClose(fileNumber)
Next

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

不支援這個函式。

需求

命名空間 (Namespace)︰Microsoft.VisualBasic

**模組︰**FileSystem

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

請參閱

參考

FileOpen 函式

IOException

其他資源

在 Visual Basic 中寫入檔案