FileAttr Function |
Named Arguments
Yes
Syntax
FileAttr(filenumber, [returntype])
filenumber
Use: Required
Data Type: Integer
Any valid file number.
returntype
Use: Required
Data Type: Integer
An optional number specifying the information to return; if you omit the argument, its value defaults to 1.
Return Value
If you specify a returntype of 1, the file access mode is returned as a long integer, as shown in the following table:
Mode | Value |
---|---|
Input | 1 |
Output | 2 |
Random | 4 |
Append | 8 |
Binary | 32 |
Description
Determines the file access mode for a file opened using the Open statement. When used on a 16-bit Windows system, FileAttr can also obtain an operating-system file handle.
Rules at a Glance
Use a returntype of 1 to obtain a return value that indicates the mode in which the file was opened.
On 16-bit Windows systems only, use a returntype of 2 to obtain an operating system file handle for the file.
Programming Tips and Gotchas
File handles—the numbers by which files are identified by the operating system—are assigned by the operating system. In contrast, the application-defined file number used in the Open statement or returned by the FreeFile function is simply a pointer into an internal table of file handles maintained by Visual Basic. In other words, the file number that references a file in a 16-bit Visual Basic program is really a pseudo-handle that is local to the program. By calling the FileAttr function with a returnvalue of 2, you can obtain the systemwide file handle. This ...
Get VB & VBA in a Nutshell: The Language now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.