Console

Console


Provides a mechanism for handling input and output for either a screen or Stream.


Public:

Types:

NameDescription
 ConsoleBreakType A list of break types returned by the console.  
 ConsoleColor The set of colors used to foreground and background color settings of the console.  

Properties:

NameDescription
 BackgroundColor (get) Returns the current background color.  
 BackgroundColor (let) Sets the background color.  
 Break (get) Returns if a break has been caused.  
 Break (let) Sets the break flag.  
 BreakType (get) Returns the cause of the break event in the console  
 BufferHeight (get) Returns the current height of the underlying screen buffer in characters.  
 BufferHeight (let) Sets the height of the underlying screen buffer in characters.  
 BufferWidth (get) Returns the current width of the underlying screen buffer in characters.  
 BufferWidth (let) Sets the width of the underlying screen buffer in characters.  
 CapsLock (get) Returns the state of the Caps-Lock key.  
 CursorLeft (get) Returns the left coordinate of the cursor position.  
 CursorLeft (let) Sets the left coordinate of the cursor position.  
 CursorSize (get) Returns the size (height) of the cursor.  
 CursorSize (let) Sets the size (height) of the cursor.  
 CursorTop (get) Returns the top coordinate of the cursor position.  
 CursorTop (let) Sets the top coordinate for the cursor position  
 CursorVisible (get) Returns whether or not the cursor is currently invisible.  
 CursorVisible (let) Sets if the cursor is visible or not.  
 Error (get) Returns the Error output currently being used by the Console.  
 ForegroundColor (get) Returns the current foreground color.  
 ForegroundColor (let) Sets the foreground color.  
 In_ (get) Returns the input source currently used by the Console.  
 InputEncoding (get) Returns the encoding used for the input from the console.  
 InputEncoding (set) Sets the encoding used during input from the console.  
 KeyAvailable (get) Returns if a key has been pressed and is available to be read in using one of the read methods.  
 LargestWindowHeight (get) Returns the largest height the viewable window could be set to.  
 LargestWindowWidth (get) Returns the largest width the viewable window could be set to.  
 NumLock (get) Returns the state of the Num-Lock key.  
 Out (get) Returns the output writer currently being used by the Console.  
 OutputEncoding (get) Returns the encoding for the current console output.  
 OutputEncoding (set) Sets the encoding for the console output.  
 Title (get) Returns the console title of the current process.  
 Title (let) Sets the title for the console of the current process.  
 TreatControlCAsInput (get) Returns if the Control+C combination is managed by the system or returned as keyboard input.  
 TreatControlCAsInput (let) Sets if the Control+C combination is managed by the system or returned as keyboard input.  
 WindowHeight (get) Returns the height of the viewable window in the screen buffer.  
 WindowHeight (let) Sets the height of the viewable window in the screen buffer.  
 WindowLeft (get) Returns the left coordinate of the console window within the screen buffer in character columns.  
 WindowLeft (let) Sets the left coordinate of the console window within the screen buffer in character columns.  
 WindowTop (get) Returns the top of the viewable window within the screen buffer.  
 WindowTop (let) Sets the top of the viewable windwo within the screen buffer.  
 WindowWidth (get) Returns the width of the window in characters.  
 WindowWidth (let) Sets the width of the viewable window within the screen buffer.  

Methods:

NameDescription
 Beep Produces a beep through the console.  
 Clear Clears the console screen and window.  
 ClearBufferArea Clears a specificed region in the screen buffer.  
 FillBufferArea Fills a specified region in the screen buffer with a character and color attributes.  
 MoveBufferArea Moves one section of the screen buffer to another location within the screen buffer.  
 OpenStandardError Returns the standard error stream.  
 OpenStandardInput Returns the standard input stream.  
 OpenStandardOutput Returns the standard output stream.  
 Read Reads a character from the current input source.  
 ReadKey Reads a single key from the console input.  
 ReadLine Reads all of the characters from the current input source until a NewLine break is reached.  
 ResetColor Restores the foreground and background colors to their original values.  
 SetBufferSize Sets the size of the underlying screen buffer.  
 SetCursorPosition Sets the position of the cursor within the screen buffer.  
 SetError Sets the Console error output stream to the supplied TextWriter object.  
 SetIn Sets the Console input source to a new TextReader object.  
 SetOut Sets the Console output to a new output TextWriter object.  
 SetWindowPosition Sets the position of the viewing window within the console screen buffer.  
 SetWindowSize Sets the size of the viewable window area for the console buffer.  
 WriteLine Writes a value to the current output stream.  
 WriteValue Writes a string to the Console output stream without a NewLine break.  

Remarks

Using the Console class allows input and output to a console window. By default, a VB6 application will create a new console window for the Console class to use. Most times it is desired to run an application in an already open console window. If a VB6 application is run from within an existing console window, a new window will be created again. To have the VB6 application to use the console window from which is it run, the EXE needs to be converted to a console application. This can be accomplished by hand using the Link program that is included with Visual Basic 6. In a console window use the following command:

link /edit /subsystem:console Application Name

Be sure the Link and application are both in paths the console window can find. Once the command has been executed, the VB6 application will run inside the console window from which it was run. If no window existed, then a new one will be created.

The Console can be used to display text on the screen, and retrieve user input from a keyboard. The input and output can be redirected to a new source to allow for reading and writing from a specified Stream.

WARNING: Do not close the console through with Close Window button while working in the IDE. This will cause the IDE to crash and all data will be lost.

 Console.BackgroundColor = Blue
 Console.WriteLine "hello"
 Console.ResetColor
 

See Also

Project CorLib Overview

Class Console Overview

ConsoleKeyInfo