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[]

オプション。 ファイルに書き込む 1 つ以上のコンマ区切り式。

この例では、 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."

注釈

Write関数とWriteLine関数は下位互換性のために用意されており、パフォーマンスに影響する可能性があります。 レガシ 以外のアプリケーションの場合、 My.Computer.FileSystem オブジェクトのパフォーマンスが向上します。 詳細については、「File Access with Visual Basic」を参照してください。

Outputを省略すると、空白行がファイルに出力されます。 複数の式をコンマで区切ることができます。

Print関数とは異なり、Write関数は、ファイルに書き込まれる文字列の周囲に項目と引用符の間にコンマを挿入します。 明示的な区切り記号をリストに含める必要はありません。 Writeを使用してデータをファイルに書き込む場合、数値、Boolean、日付、null、およびErrorのデータ形式のみがサポートされます。 ロケールに関係なく、常に Inputを使用してデータを読み取り、正しく解釈できるように、次の一般的な前提条件に従います。

  • 数値データは、小数点記号としてピリオドを使用して常に書き込まれます。

  • Booleanデータの場合は、#TRUE#または#FALSE#が印刷されます。 ロケールに関係なく、 True キーワードと False キーワードは翻訳されません。

  • 日付データは、ユニバーサル日付形式を使用してファイルに書き込まれます。 日付または時刻のコンポーネントが見つからないか、0 の場合、指定された部分のみがファイルに書き込まれます。

  • データが空の場合、ファイル 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の値を持つ文字列を返します。

WriteまたはWriteLine関数を使用してファイルに書き込むには、FileIOPermissionAccess列挙体からのAppendアクセスが必要です。 詳細については、「FileIOPermissionAccess」を参照してください。

適用対象

こちらもご覧ください