Write, WriteLine Functions
Writes data to a sequential file. Data written with Write is usually read from a file with Input.
Public Sub Write( _ ByVal FileNumber As Integer, _ ByVal ParamArray Output As Object _ )
Public Sub WriteLine( _ ByVal FileNumber As Integer, _ ByVal ParamArray Output() As Object _ )
- Required. An Integer expression containing any valid file number.
- Optional. One or more comma-delimited expressions to write to a file.
|Exception type||Error number||Condition|
|IOException||52||FileNumber does not exist.|
|IOException||54||File mode is invalid.|
If you omit Output, a blank line is printed to the file. Multiple expressions can be separated with a comma.
Unlike the Print function, the Write function inserts commas between items and quotation marks around strings as they are written to the file. You don't have to put explicit delimiters in the list. When Write is used to write data to a file, only the following data formats are supported and several universal assumptions are followed so the data can always be read and correctly interpreted using Input, regardless of locale:
- Numeric data is always written using the period as the decimal separator.
- For Boolean data, either
#FALSE#is printed. The True and False keywords are not translated, regardless of locale.
- Date data is written to the file using the universal date format. When either the date or the time component is missing or zero, only the part provided gets written to the file.
- Nothing is written to the file if Output data is empty. However, for null data,
- For Error data, the output appears as
#ERROR errorcode#. The Error keyword is not translated, regardless of locale.
WriteLine inserts a newline character (that is, a carriage return–linefeed, or
Chr(13) + Chr(10)), after it has written the final character in Output to the file.
You can embed quotation marks in a string by using double quotation marks, or "". For example,
Dim x As String = "Double quotation marks aren't ""difficult"" to handle."
returns a string with the value of Double quotation marks aren't "difficult" to handle.
Writing to a file with the Write or WriteLine functions requires Append access from the FileIOPermissionAccess enumeration. For more information, see FileIOPermissionAccess Enumeration.
This example uses the Write function to write raw data to a sequential file.
FileOpen(1, "TESTFILE", OpenMode.Output) ' Open file for output. Write(1, "This is a test.") ' Print text to file. WriteLine(1) ' Print blank line to file. WriteLine(1, "Zone 1", TAB(), "Zone 2") ' Print in two print zones. WriteLine(1, "Hello", " ", "World") ' Separate strings with space. WriteLine(1, SPC(5), "5 leading spaces ") ' Print five leading spaces. WriteLine(1, TAB(10), "Hello") ' Print word at column 10. ' Assign Boolean, Date, and Error 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") FileClose(1) ' Close file.
Smart Device Developer Notes
This function is not supported.
Assembly: Microsoft Visual Basic .NET Runtime (in Microsoft.VisualBasic.dll)