Repository navigation
Input File Mode
Home › File I/O Functions › Input (File Mode)
Opens a text file for reading with Open; the file must already exist.
Open filename for Input [Encoding encoding_type] [Lock lock_type] as [#]filenumfilenameencoding_typelock_typefilenum
A file mode used with Open to open a text file for reading.
This mode allows to read sequentially lines of text with Line Input #, or to read comma separated values with Input #.
Text files can't be simultaneously read and written in FreeBASIC, so if both functions are required on the same file, it must be opened twice.
filename must be a string expression resulting in a legal file name in the target OS, without wildcards. The file will be sought for in the present directory, unless the filename contains a path . If the file does not exist, an error is issued. The pointer is set at the first character of the file.
Encoding_type indicates the Unicode Encoding of the file, so characters are correctly read. If omitted, "ascii" encoding is defaulted. Only little endian character encodings are supported at the moment.
Lock_type indicates the way the file is locked for other processes, it is one of:
filenum is a valid FreeBASIC file number (in the range 1..255) not being used for any other file presently open. The file number identifies the file for the rest of file operations. A free file number can be found using the FreeFile function.
Dim ff As UByte
Dim randomvar As Integer
Dim name_str As String
Dim age As Integer
'' collect the test data and output to file with Write #
Input "What is your name? ", name_str
Input "What is your age? ", age
Randomize
Print
ff = FreeFile
Open "testfile" For Output As #ff
Write #ff, Int(Rnd*42), name_str, age
Close #ff
'' clear variables
randomvar = 0
name_str = ""
age = 0
'' input the variables, using Input #
ff = FreeFile
Open "testfile" For Input As #ff
Input #ff, randomvar, name_str, age
Close #ff
Print "Random Number was: " & randomvar
Print "Your name is: " & name_str
Print "Your age is: " & age
'File outputted by this sample will look something like this
'(not including the leading comment marker):
'23,"Your Name",19Category: 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.
- Home
- What Is tiko-lang
- Quick Start
- Installing on macOS
- Debugging
- Feature Index
- Compatibility
- FAQ
- AI Cheatsheet
- 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)
- Time Zones
- 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