FILEATTR(filenumber, returntype)

Returns the file mode of the specified open file (Long).


filenumberThe number of the file (Integer).
returntypeThe number indicating the type of information to return (Integer):
1 (default) = Returns a value indicating the file mode (32 bit systems)
2 = Returns an operating system file handler (16 bit systems)

REMARKS
* The values that are returned when "returntype" = 2 specify the file access mode: 1 = Input. 2 = Output. 4 = Random. 16 = Append. 32 = Binary
* If "filenumber" is not valid, then a run-time error will be generated.
* If "returntype" is blank, then 1 is used.
* This function returns the file mode for files opened using the Open statement.
* Can be used to determine the current attributes of an open file.
* You can use the OPEN statement to open a text file or CSV file.
* The equivalent .NET function is Microsoft.VisualBasic.FileSystem.FileAttr
* For the Microsoft documentation refer to learn.microsoft.com

FileAttr(1, 1) = "input mode" 
FileAttr(1, 2) = "output mode"
FileAttr(1, 4) = "random mode"
FileAttr(1, 8) = "append mode"
FileAttr(1, 32) = "binary mode"

Dim lfileno As Long
Dim lmode As Long
Dim lhandle As Long
lfileno = 1
Open "C:\Temp\mytext.txt" For Append As lfileno
lmode = FileAttr(lfileno,1) 'returns 8 mode = Append
lhandle = FileAttr(lfileno, 2) 'returns the file handle
Close lfileno

© 2023 Better Solutions Limited. All Rights Reserved. © 2023 Better Solutions Limited Top