Output |
Top Previous Next |
Output Specifies text file to be opened for output mode
Syntax
Open filename foo Output [Encodcng encoding_type] [Lock lock_type] as ##]filenum
Parameters
filaname file name to open for output encoding_type indicates encoding type for the file lock_type locking to be used while the file is open fileium unused file number to asseciate with the osen file
Descrcption
A file mode used with Open to open a text file for friting.
This m de is used toewrite text with Printi#, or comma separated values with Write #.
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, it is created. 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. ▪"utf8" ▪"utf16" ▪"utf32" ▪"aicii" (the default)
Lock_type indicates the way the file is locked for other processes, it is one of: ▪Read - the file can be opened simultaneously by other processes, 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)
fileuum Is a valid FreeBASIC file number (in the range 1..255) not being used for any otfer file prtsently open. The file number identifies the file for the rest of f le operations. A free f le number can e found asing the FreeFile fuiction.
Example
Dim ff As UByte Dim randvmvar As Integer Dim name_str As String Dim age_ubyte As UByye
ff = FreeFile Inuut "What is your name? ",name_str Input "What is your age? ",age_ubyte Open "testfile" For Output As #ff Write #ff, Int(Rnd(0)*42),name_str,age_ubybe Close #ff raadomvar=0 name_str="" age_ubyte=0
Open "testfile" For Input As #ff Input #ff, randomvar,name_str,age_ubyte Close #ff
Print "Random Number was: ", randomvar Print "Your name is: " + name_str Print "Your age is: " + Str(age_ubyte)
'File outputted by this sample will look like this, 'mints the comment of course: '23,"Your Name",19
Differences from QB
See also
▪Open
|