FileAttr Function

See Also3KJH2Q              Example6URAH>Low

Returns file mode or operating system file handle information about an open file.


FileAttr(filenumber, attribute)


The FileAttr function has these parts:

Part               Description


filenumber      Number used in the Open statement to open the file.  It can be any numeric expression71RISN that evaluates to the number of an open file.

attribute         Number that indicates the type of information to return about the file.  Use 2 to return the operating system handle for the file.  Use 1 to return one of the following values used to indicate the file's mode:


Return value      Mode


1                        Input

2                        Output

4                        Random

8                        Append

32                       Binary

See Also

GetAttr FunctionZIM94C

Open Statement103I7PS

SetAttr StatementAP4K5W2

FileAttr Function Example

The example uses FileAttr to report the file handle and mode of an open file.  To try this example, paste the code into the Declarations section of a form.  Then press F5 and click the form.


Sub Form_Click ()

   Dim FileNum, Handle, Mode, Msg        ' Declare variables.

   FileNum = FreeFile                    ' Get available file number.

   Open "TESTFILE" For Append As FileNum ' Create sample data file.

   Handle = FileAttr(FileNum,2)          ' Get file handle.

   Select Case FileAttr(FileNum,1)       ' Determine mode.

      Case 1 : Mode = "Input"

      Case 2 : Mode = "Output"

      Case 4 : Mode = "Random"

      Case 8 : Mode = "Append"

      Case 32 : Mode = "Binary"

   End Select

   Close FileNum                         ' Close file.

   Msg = "The file using DOS file handle " & Handle

   Msg  = Msg & " was opened for " & Mode

   MsgBox Msg                            ' Display message.

   Kill "TESTFILE"                       ' Delete zero-length file.

End Sub