Get File Mode Method
The Get File Mode method returns the file mode or the operating system handle for an open file. The following table describes this return value.
Value of Returntype Argument | Description of the Return Value |
---|---|
1 |
The file mode of the open file:
|
2 |
The operating system handle of the open file. |
Format
FileAttr(filenumber, returntype)
The following table describes the arguments that you can use with this method.
Argument | Description |
---|---|
filenumber |
The file number that the Open statement uses to open the file. |
returntype |
An integer that identifies the type of information to return. |
Example
The following example does one of the following:
If the open file is in input mode or output mode, then it closes this open file.
If the open file is in append mode, then it writes a range of numbers to this file.
The CreateFile subroutine creates the file and leaves it open:
(general) (declarations)
Option Explicit
Declare Sub CreateFile
Sub CreateFile
Rem Put the numbers 1-10 into a file
Dim x as Integer
Open "c:\temp001" for Output as #1
For x = 1 to 10
Write #1, x
Next x
End Sub
Sub Button_Click
Dim filemode as Integer
Dim attrib as Integer
Call CreateFile
attrib = 1
filemode = FileAttr(1,attrib)
If filemode = 1 or 2 then
Close #1
Else
For x = 11 to 15
Write #1, x
Next x
Close #1
End If
Kill "c:\temp001"
End Sub