Open Instruction

Syntax

Open Name$ For mode [Access access] [lock] As _
    [#]StreamNum [Len = RecordLen]

Group

File

Description

Opens file Name$ for mode as StreamNum.

Reading Unicode Files

To read a Unicode (UTF-16 or UTF-8) file, just open using Input mode. All the input is converted automatically.

Writing Unicode Files

To write a Unicode (UTF-16 or UTF-8) file, open Output or Append mode and write the appropriate Byte Order Mark (BOM). All printed output is converted automatically.

To create a Unicode (UTF-16) text file, use the following:

Open FileName$ For Output As #fn
Print #fn, vbUTF16BOM; ' first char is the UTF-16 Byte Order Mark
... ' everything automatically converted to UTF-16
Close #fn

To create a Unicode (UTF-8) text file, use the following:

Open FileName$ For Output As #fn
Print #fn, vbUTF8BOM; ' first three chars are the UTF-8 Byte Order Mark
... ' everything automatically converted to UTF-8
Close #fn

Pocket PC

Access and lock ignored.

Parameters

Parameters Description
Name$ The path and name of the file. You can use a path relative to the current directory.
mode Can be Input, Output, Append, Binary, or Random.
access Can be Read, Write, or Read Write. (Only allowed for Binary and Random modes.)
lock Can be Shared, Lock Read, Lock Write, or Lock Read Write.
StreamNum Streams 1 through 255 are private to each macro. Streams 256 through 511 are shared by all macros.
RecordLen The record length for Random mode files. Other file modes ignore this value.

Example


Sub Main
    Open "XXX" For Output As #1
    Print #1, "1,2,""Hello"""
    Close #1
End Sub

See also

Close, FileAttr, FreeFile, Open, Reset