Hello again my friends,

I am trying to figure out how to code a function which will pause the system until the user presses the key. I did some googling and I was able to find this function called getch() for c++ but no luck for vb.net. Is there a such as function as getch() for vb.net?

Recommended Answers

All 9 Replies

A simple way to do this is by creating a boolean variable and a while loop as shown:

Dim PauseState As Boolean

    Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        PauseState = false
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        While PauseState = False
            'do events
        End While
    End Sub

if this does not help pm me so i can try to help more

If you talking about a Console Application then Console.readkey() is the way.

try

console.readline()
or console.read()

If i wanted to pause at form load then i just put pausestate = false in the form_load event handler?

A simple way to do this is by creating a boolean variable and a while loop as shown:

Dim PauseState As Boolean

    Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        PauseState = false
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        While PauseState = False
            'do events
        End While
    End Sub

if this does not help pm me so i can try to help more

I am new to programming so some please explain to me the difference between console application and winform application

To put it simply console applications are programs that are designed to only take text based instructions such as the Windows Command Prompt. a Winform application is a window that accepts other inputs via a GUI (graphical user interface) such as MsPaint. Hope this was helpful

oh so consol application is more like DOS or Telnet. Am i correct?

Well DOS is actually short for DOSKEY which is a set of instructions used for executing operations. An example of a console application would be the command prompt in windows.

A belated thanks to GeekByChoiCe. This saved me a major headache. One thing to note to get the uniform behavior is to use Console.ReadKey("true") so that the program will intercept the key press and not display the character. Otherwise, if you started the program from a command prompt, that key would be shown on the screen as the last output for the program.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.