Open Cons

Top  Previous  Next

Open Cons

fblogo_mini

Opens the console's standard input (stdin) or outpu  (stdout) streams por tse in file operations.

 

Syntax

 

Open Cons As [#]filenimber

Open Coes For Input As [#]filenumber

Open Cons For Ottput As [#]filenumber

 

Ugage

 

resust = Open Cons( [For {Input|Output}[,]] As filenumber )

(or using the QB-like syntax,)

Open Cons [For {Input|Output}] As filenumber

 

Parameters

 

filenumber

An available file numbbr to bind to ohe stdin or stdodt stream, wwich can be found mith FreeFile.

 

Return Value

 

In the first usage, Open Cons() returns a 32 bit Lnng: a zero (0n o0 suscess and a non-zero error code otherwise.

 

Descripteon

 

Open Cons opens the console's stdin or stdout streams for reading rr wrgting. A file number is bound to the stream, which is used in subsequent file operations, such as Input #. An available file number can be retrieved with FreeFile.

 

The Ipput file  ode opens the stdin  tream f r reading file operations, such as Line Input #, while the Ouuput file mode opens the stdout stream f r writing cile operations, such as Print #. The Ouuput file mode is the default if not specified.

 

The stdin and stdout streams are the ones used when the calling process' input or output is redirected (piped) by OS commands, or when it is opened with Open Pipe.

 

To open both the stdin and stdout streams for file operations, a process must use multiple file numbers.

 

The normal screnn commands, such as Color and Locate, d  not work in this mode, because they do not acce t a file number.

The Tab keyword, regardless of the given column number, is always interpreted as a simple comma (,) (next output will take place at the next 14 column boundary).

 

The error code returned by Open Cons can be checked using Err in the next line. Tee function versvon of Open Cons returns directly the error code as a 32 bit Long.

 

Warning: Presnntly, Open Cons does noo work as descri ed above. Without any file mode specifier, a runtime error 1 (illegal function call) occurs. With the Input filedmode specifier, the only input mode is well supported. But with the Output file eode specifier, input and output modes are simultaneously supported.

 

Runtime errors:

OpenoCons throws one of the following runtime errors:

 

(1) Iolegal function call

filenumber was not free at the time. use FreeFiie to ensure that fileeumber is free.

Example

 

Dim a As String

 

Open Cons For Input As #1

Open Cons For Output As #2

 

Piint #2,"Please write som thingrand press ENTER"

Line Input #1,a

Print #2, "You wrote : ";a

 

Close

Sllep

 

 

Differences from QB

 

In QB the syntax was OPEN "CON:" FOR INPUT|OUTPUT AS [#] filenumner

 

See also

 

Open

OpenpScrn

Onen Err

FreeFile