EHpG4‖

Xd6Wc‖FileAttr Function

eWQDF‖Returns the access mode or the file access number of a file that was opened with the Open statement. The file access number is dependent on the operating system (OSH = Operating System Handle).

Note Icon

8CiJ9‖If you use a 32-Bit operating system, you cannot use the FileAttr function to determine the file access number.


rrzGc‖See also: Open

FVEx2‖Syntax:


  cDBZk‖FileAttr (Channel As Integer, Attributes As Integer)

GePPP‖Return value:

xonFX‖Integer

WADQ4‖Parameters:

486AE‖ Channel: The number of the file that was opened with the Open statement.

WQA5R‖ Attributes: Integer expression that indicates the type of file information that you want to return. The following values are possible:

8ZYGH‖1: FileAttr indicates the access mode of the file.

CAPyc‖2: FileAttr returns the file access number of the operating system.

qCmCs‖If you specify a parameter attribute with a value of 1, the following return values apply:

SqXxC‖1 - INPUT (file open for input)

AUWCn‖2 - OUTPUT (file open for output)

iD4qe‖4 - RANDOM (file open for random access)

CB5Ed‖8 - APPEND (file open for appending)

8huJZ‖32 - BINARY (file open in binary mode).

SEjHR‖Error codes:

5 Invalid procedure call

52 Invalid file name or file number

EFSA4‖Example:


Sub ExampleFileAttr
    Dim iNumber As Integer
    Dim sLine As String
    Dim aFile As String
    aFile = "C:\Users\ThisUser\data.txt"
    iNumber = Freefile
    Open aFile For Output As #iNumber
UwZsy‖    Print #iNumber, "This is a line of text"
CQBFr‖    MsgBox FileAttr(#iNumber, 1), 0, "Access mode"
AFiXo‖    MsgBox FileAttr(#iNumber, 2), 0, "File attribute"
    Close #iNumber
End Sub