Console: Read

Read

Reads a character from the current input source.



 Public Function Read ( ) As Long

Return Values

Long -  The next character read from the input source, or -1 if no more characters exists.

Remarks

The Read method does not return until the Return key is pressed. Once the function returns, it can be called repeatedly until all key presses upto the return key are retrieved. The return key is also returned as a carriage-return (13) followed by a line-feed (10).

Example

This example shows how to read input from the console keyboard. The Read function will block and wait for the return key to bepressed before returning. If there are characters already in theinput stream, the function does not block and returns the next character.
Private Sub Main()    Dim ch As Long        ' reads from the console keyboard. The function    '' will block until the return key is pressed.    ch = Console.Read        '' we will loop through the characters typed into    '' the console and exit the loop when CTRL+Z followed    '' by Return is pressed.    Do While ch <> 26        Debug.Print Chr$(ch);        DoEvents                '' As long as there are characters remaining to be        '' from the console keyboard, this function won't block.        ch = Console.Read    LoopEnd Sub
As shown here, the loop just retrieves characters from the consolekeyboard one character at a time. If there are no more charactersin the buffer, then the Read function will block and wait for theReturn key to be pressed again. The key combination of CTRL+Z (26)is used as an exit from the loop. CRTL+Z is what is usedto signal the end of a file on unix platforms.

See Also

Project VBCorLib Overview Class Console Overview Console Properties Console Methods OutputEncoding (set) ReadKey