Share via


FileSystem.WriteLine(Int32, Object[]) 方法

定義

將資料寫入循序檔。 使用 Write 寫入的資料,通常會透過使用 Input 從檔案讀取。

public:
 static void WriteLine(int FileNumber, ... cli::array <System::Object ^> ^ Output);
public static void WriteLine (int FileNumber, params object[] Output);
static member WriteLine : int * obj[] -> unit
Public Sub WriteLine (FileNumber As Integer, ParamArray Output As Object())

參數

FileNumber
Int32

必要。 包含任何有效檔案數目的 Integer 運算式。

Output
Object[]

選擇性。 要寫入檔案的一或多個逗點分隔運算式。

範例

此範例會使用函式將 Write 原始數據寫入循序檔案。

' Open file for output.
FileOpen(1, "TestFile.txt", OpenMode.Output)
' Print text to the file. The quotation marks will be in the display.
Write(1, "This is a test.")
' Go to the next line.
WriteLine(1)
' Skip a line.
WriteLine(1)
' Print in two print zones. You will see commas and quotation marks
' in the output file.
WriteLine(1, "Zone 1", SPC(10), "Zone 2")
' Build a longer string before calling WriteLine.
WriteLine(1, "Hello" & "  " & "World")
' Include five leading spaces.
WriteLine(1, SPC(5), "Leading spaces")
' Print a word starting at column 10.
WriteLine(1, TAB(10), "Hello")

' Assign Boolean and Date values.
Dim aBool As Boolean
Dim aDate As DateTime
aBool = False
aDate = DateTime.Parse("February 12, 1969")

' Dates and Booleans are translated using locale settings of 
' your system.
WriteLine(1, aBool & " is a Boolean value.")
WriteLine(1, aDate & " is a date.")
' Close the file.
FileClose(1)

' Contents of TestFile.txt
'"This is a test.",
'
'"Zone 1",          "Zone 2"
'"Hello  World"
'     "Leading spaces"
'         ,"Hello"
'"False is a Boolean value."
'"2/12/1969 is a date."

備註

WriteWriteLine 函式是針對回溯相容性而提供,而且可能會影響效能。 針對非舊版應用程式, My.Computer.FileSystem 物件可提供更佳的效能。 如需詳細資訊,請參閱 Visual Basic 的檔案存取

如果您省略 Output,則會將空白行列印至檔案。 您可以使用逗號分隔多個運算式。

不同於函 Print 式,函式會在 Write 字串周圍插入逗號,因為它們會寫入檔案。 您不需要在清單中放置明確的分隔符。 當 Write 用來將數據寫入檔案時,僅支持數值、 Boolean、日期、Null 和數據 Error 格式。 遵循下列通用假設,因此不論地區設定為何,數據一律可以使用 讀取並正確解譯 Input

  • 數值數據一律會使用句號做為小數分隔符來寫入。

  • 如果是 Boolean 資料,則會 #TRUE# 列印 或 #FALSE#True不論地區設定為何,都不會轉譯 和 False 關鍵詞。

  • 日期數據會使用通用日期格式寫入檔案。 當日期或時間元件遺失或零時,只會將提供的元件寫入檔案。

  • 如果 Output 數據是空的,則不會寫入檔案。 不過,如果是 Null 數據, #NULL# 則會寫入。

  • 針對 Error 資料,輸出會顯示為 #ERROR errorcode#。 不論地區設定為何,關鍵詞 Error 都不會翻譯。

WriteLine會在將最後一個字元Output寫入檔案之後,插入換行字元 (,也就是歸位字元/換行字元或 Chr(13) + Chr(10)) 。

您可以使用雙引號或 「在字串中內嵌引號」。 例如,

Dim x As String = "Double quotation marks aren't ""difficult"" to handle."

傳回值為 的 Double quotation marks aren't "difficult" to handle字串。

使用 WriteWriteLine 函式寫入檔案時,需要 Append 從 列舉存取 FileIOPermissionAccess 。 如需詳細資訊,請參閱FileIOPermissionAccess

適用於

另請參閱