Write# Statement

Writes data to a sequential text file with delimiting characters.


Use Print# statement to print data to a sequential text file. Use Put# statement to write data to a binary or a random file.


Write Statement diagram

Write [#fileNum] {,|;} expression [, …]


fileNum: Any numeric expression that contains the file number that was set by the Open statement for the respective file.

expression list: Variables or expressions that you want to enter in a file, separated by commas.

如果省略了表示式清單,Write 陳述式會附加至檔案的空行。

若要將表示式清單加入新檔案或現有檔案中,必須以 Output 模式或 Append 模式開啟檔案。


每個 Write 陳述式會輸出行結束符號做為最後的輸入。



Sub ExampleWrite
    Dim iCount As Integer
    Dim sValue As String
    iCount = Freefile
    Open "C:\data.txt" For Output As iCount
    sValue = "Hamburg"
    Write #iCount,sValue,200
    sValue = "New York"
    Write #iCount,sValue,300
    sValue = "Miami"
    Write #iCount,sValue,450
    Close #iCount
End Sub

Please support us!