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 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.

See Also

Open Statement, File System Object
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset