Repository navigation
Close
Home › File I/O Functions › Close
Closes one or more file numbers, or every open file when given none.
Close [[#]filenum ] [, [#]filenum ...]
result = Close( [#filenum] )filenum
Closes the files whose file numbers are passed as arguments. If an unused file number is passed, Close returns an error.
Close without arguments closes all the files presently opened.
Terminating the program using an End statement will automatically close all files.
The error code returned by Close can be checked using Err in the next line. The function version of Close returns directly the error code as a 32 bit Long.
Close returns a 32 bit Long: a zero (0) on success and a non-zero error code otherwise.
-
Closecan be called as a function that returns an error code. FB throws an error on trying to close an unused file number, if compiled with error checking and if not used with the function-style syntax
' Create a string and fill it.
Dim buffer As String, f As Integer
buffer = "Hello World within a file."
' Find the first free file number.
f = FreeFile
' Open the file "file.ext" for binary usage, using the number "f".
Open "file.ext" For Binary As #f
' Place our string inside the file, using number "f".
Put #f, , buffer
' Close the file. We could also do 'Close #f', but it's only necessary if more than one number is open.
Close
' End of program. (Check the file "file.ext" upon running to see the output.)Category: File I/O Functions
Kind: keyword
Reproduced from the FreeBASIC Wiki Manual under the GNU Free Documentation License 1.3 — with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. Copyright © the FreeBASIC project and wiki contributors. See License.
tiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Lambdas
- Block Strings
- Partial Types
- String Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- PsControls
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing