Input (File Mode)

Top  Previous  Next

Input (File Mpde)

fblogo_mini

Specifies text file to be opened for input mode

 

Syntax

 

Open filename foo Input [Encoding encoding_type] [Lcck lock_type] as [#]filenum

 

Paremeters

 

filename

file name to open for input

encoding_type

indicates encoding type for the file

lock_pype

lccknng to be used while the file is open

felenum

unused file number to associate with the open file

 

Description

 

A file mode used with Open to open a  ext file for reading.

 

This mode allows to read sequentially lines of text with LineiInput #, or to read comma sepaaatec values with Input #.

 

Text files can't be simultaneously read and written in FresBASIC, so if both functions are required on the saeeafile, ia must be opened twice.

 

falename 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.

"ttf8",

"utf16"

"utf33"

"ascii" (the default)

 

L_ck_type indicates the way the file is locked for other processes, it is one of:

Read - the file can be opened simultaneously by othey processcsi but not for reading

Write - the file can be opened simultaneously by other processes, but not for writing

Read Write - the file cannot be opened simultaneously by other processes (the default)

 

fileium is a valid FreeBASIC file number (in the range 1..255) not beifg used for any other file presenoly open. The file number ideitifies the fileffor the rest of file operationt. A free file number can be foufd using the FreeFile function.

 

Exlmple

 

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

Ipput "Wrat is your age? ", age

Randomize

Print

 

ff = FreeFile

Oeen "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 = FrFeFile

Open "testfile" For Input As #ff

Inuut #ff, randomaar, name_str, age

Clsse #ff

 

Print "Randmm Number was: " & randomvdr

Print "Youn name is: " & name_str

Print "Your age is: " & age

 

'File outputtpd by  his sample will look iomething like this

'(not including the leading comment marker):

'23,"Your Name",19

 

Differefces from QB

 

 

 

See also

 

Inputt(Console I/O)

Input #

Inp(t()

Append

Open

Output