Funkcja FileAttr

Zwraca tryb dostępu lub numer dostępu do pliku otwartego przez instrukcję Open. Numer dostępu do pliku zależy od systemu operacyjnego (OSH = Operating System Handle).

Ikona notatki

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


Zobacz także: Open

Składnia:


  FileAttr (Channel As Integer, Attributes As Integer)

Zwracana wartość:

Liczba całkowita

Parametry:

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

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

1: FileAttr indicates the access mode of the file.

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

Nadanie wartości 1 atrybutowi parametru pozwala na uzyskanie następujących wartości wynikowych:

1 - INPUT (otwarcie pliku w trybie wejścia)

2 - OUTPUT (otwarcie pliku w trybie wyjścia)

4 - RANDOM (otwarcie pliku w trybie dostępu bezpośredniego)

8 - APPEND (otwarcie pliku w trybie dopisywania)

32 - BINARY (otwarcie pliku w trybie binarnym).

Kody błędów:

5 Nieprawidłowe wywołanie procedury

52 Nieprawidłowa nazwa pliku lub numer pliku

Przykład:


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
    Print #iNumber, "To jest linia tekstu"
    MsgBox FileAttr(#iNumber, 1), 0, "Access mode"
    MsgBox FileAttr(#iNumber, 2), 0, "File attribute"
    Close #iNumber
End Sub