Fungsi FileAttr

Mengembalikan mode akses atau nomor akses file dari file yang sudah dibuka dengan pernyataan Open. Nomor akses file tergantung pada sistem operasi (OSH = Operating System Handle).

Ikon Catatan

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


Lihat juga: Buka

Sintaksis:


  FileAttr (Channel As Integer, Attributes As Integer)

Nilai balikan:

Integer

Parameter:

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.

Jika anda menentukan atribut parameter dengan nilai 1, diterapkan nilai pengembalian seperti berikut:

1 - INPUT (berkas dibuka untuk masukan)

2 - OUTPUT (berkas dibuka untuk keluaran)

4 - RANDOM (berkas dibuka untuk akses acak)

8 - APPEND (berkas dibuka untuk ditambahkan/dilampirkan)

32 - BINARY (berkas dibuka dalam mode biner).

Kode kesalahan:

5 Tidak sah dalam pemanggilan prosedur

52 Nama berkas atau angka yang buruk

Contoh:


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, "Ini adalah baris teks"
    MsgBox FileAttr(#iNumber, 1), 0, "Access mode"
    MsgBox FileAttr(#iNumber, 2), 0, "File attribute"
    Close #iNumber
End Sub

Mohon dukung kami!