FileAttr Function |
Yes
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.
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 |
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.
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.
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 can then be used when calling MS-DOS functions (like the services provided by MS-DOS interrupts) that require the file handle but don't recognize the application-defined file number.
Remember that a returntype of 2 can be used only on a 16-bit system; its use on a 32-bit system generates an error.
For 32-bit systems, the returntype argument is superfluous, since the only legal value is the default value of 1. Supplying any other value generates runtime error 5, "Invalid procedure call or argument."
The File System object model, new to VB6, includes a File object, one of whose properties is Attributes. The File object has many properties that can be queried to give far more information that the FileAttr function.