Put# Statement

相対編成ファイルへの 1 つのレコードの書き込みおよび、バイナリファイルへの 1 つのバイトシーケンスの書き込みが行えます。

tip

Use Print# statement to print data to a sequential text file. Use Write# statement to write data to a sequential text file with delimiting characters.


Syntax:

Put Statement diagram


Put [#]fileNum, [recordNum|filePos], variable

Parameters:

fileNum: Any integer expression that defines the file that you want to write to.

recordNum, filePos: For relative files (random access files), the number of the record that you want to write.

バイナリファイル (バイナリアクセス) の場合は、ファイル中の書き込みを開始するバイト位置。

variable: Name of the variable that you want to write to the file.

相対編成ファイルでの注意: この変数の内容が Open ステートメントの Len句で指定されたレコード長と一致しない場合、 新たに書き込まれたレコードの末尾から次のレコードまでの間の空間は、書き込み先ファイルの既存データで埋められます。

バイナリファイルについては、下記の点に注意が必要です。ここで指定する変数の内容は、指定位置から書き込みが開始され、データの最終バイトの次にファイルポインターが移動します。レコードの間に、スペースが残されることはありません。

Example:

Example:


Sub ExampleRandomAccess
    Dim iNumber As Integer
    Dim sText As Variant REM バリアント型変数が必要
    Dim aFile As String
    aFile = "c:\data.txt"
    iNumber = Freefile
    Open aFile For Random As #iNumber Len=32
    Seek #iNumber,1 REM 開始位置
    Put #iNumber,, "ここはテキストの始めの行です。" REM テキストで行を埋める
    Put #iNumber,, "This is the second line of text"
    Put #iNumber,, "This is the third line of text"
    Seek #iNumber,2
    Get #iNumber,,sText
    Print sText
    Close #iNumber
    iNumber = Freefile
    Open aFile For Random As #iNumber Len=32
    Get #iNumber,2,sText
    Put #iNumber,,"This is a new text"
    Get #iNumber,1,sText
    Get #iNumber,2,sText
    Put #iNumber,20,"This is the text in record 20"
    Print Lof(#iNumber)
    Close #iNumber
End Sub

ご支援をお願いします!