FileAttr 函数FileAttr function

返回Long 类型值, 表示使用**Open** 语句打开的文件的文件模式。Returns a Long representing the file mode for files opened by using the Open statement.

语法Syntax

FileAttr(filenumber, returntype)FileAttr(filenumber, returntype)


FileAttr 函数语法包含以下命名参数The FileAttr function syntax has these named arguments:

PartPart 说明Description
filenumberfilenumber 必需;类型为 IntegerRequired; Integer. 任何有效文件号Any valid file number.
returntypereturntype 必需;IntegerRequired; Integer. 指示要返回的信息类型的数值。Number indicating the type of information to return. 指定 1 将返回指示文件模式的值。Specify 1 to return a value indicating the file mode. 只在 16 位系统上,指定 2 来检索操作系统文件句柄。On 16-bit systems only, specify 2 to retrieve an operating system file handle. Returntype 2 在 32 位系统上不受支持并会导致错误。Returntype 2 is not supported in 32-bit systems and causes an error.

返回值Return values

当_returntype_ 参数为1时, 下列返回值指示文件访问模式:When the returntype argument is 1, the following return values indicate the file access mode:

模式Mode Value
InputInput 11
"输出"Output 双面2
随机Random 44
AppendAppend utf-88
BinaryBinary 3232

示例Example

此示例使用 FileAttr 函数返回打开文件的文件模式和文件句柄。This example uses the FileAttr function to return the file mode and file handle of an open file. 仅在 16 位系统上返回文件句柄;在 32 位系统上,将 2 作为第二个参数传递会生成一个错误。The file handle is returned only on 16-bit systems; on 32-bit systems, passing 2 as a second argument generates an error.

Dim FileNum, Mode, Handle
FileNum = 1    ' Assign file number.
Open "TESTFILE" For Append As FileNum    ' Open file.
Mode = FileAttr(FileNum, 1)    ' Returns 8 (Append file mode).
Handle = FileAttr(FileNum, 2)    ' Returns file handle.
Close FileNum    ' Close file.

另请参阅See also

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.