locked
application console problem RRS feed

  • Question

  • I wrote some brown code in console application Visual Studio 2015 but the console is not stable.

    It displays and closes immediately.

    Sunday, May 20, 2018 6:22 PM

Answers

  •  Are you using the Console.ReadKey or Console.ReadLine method at the end of the Sub Main to make it wait for input from the user before it exits/closes?  For example...

    Module Module1
    
        Sub Main()
            For i As Integer = 0 To 9
                Console.WriteLine(i.ToString)
            Next
            Console.WriteLine("Press any key to exit.")
    
            Console.ReadKey() 'waits for the user to press a key before exiting
        End Sub
    
    End Module
    


    If you say it can`t be done then i`ll try it

    • Marked as answer by jacob mahone Sunday, May 20, 2018 6:51 PM
    Sunday, May 20, 2018 6:33 PM

All replies

  •  Are you using the Console.ReadKey or Console.ReadLine method at the end of the Sub Main to make it wait for input from the user before it exits/closes?  For example...

    Module Module1
    
        Sub Main()
            For i As Integer = 0 To 9
                Console.WriteLine(i.ToString)
            Next
            Console.WriteLine("Press any key to exit.")
    
            Console.ReadKey() 'waits for the user to press a key before exiting
        End Sub
    
    End Module
    


    If you say it can`t be done then i`ll try it

    • Marked as answer by jacob mahone Sunday, May 20, 2018 6:51 PM
    Sunday, May 20, 2018 6:33 PM
  • good
    Sunday, May 20, 2018 6:47 PM
  • I realize the thread is answered. There's also a loop you can use to exit the app when a certain console key is entered. But it's probably not what you want.

    Or you could set Loop Until cki.Key <> ConsoleKey.Whatever. It can be used to know when arrow keys are selected for example and do something when that occurs and exit when ConsoleKey.Escape is selected if no Console.ReadKey or Console.ReadLine follows the loop.

    Module Module1
    
        Dim cki As ConsoleKeyInfo
    
        Sub Main()
            Do Until cki.Key = ConsoleKey.Escape
                Console.WriteLine("Hello")
                cki = Console.ReadKey(True)
            Loop
        End Sub
    
    End Module


    La vida loca

    Monday, May 21, 2018 3:59 AM