Search code examples
vb.netconsolebasic

How can i let my console window open? VB


I want to let my console window open in Visual Basic. With my code that i have, i only can ask for one line and then the window closes. Here is my code:

Module Module1

Sub Main()

    If (Console.ReadLine = "e") Then
        Console.WriteLine("Test")
    End If

    Console.ReadKey()

End Sub

End Module

So when i run this code i can type "e" press enter. The word appears "Test" and then the console closes after pressing one key. But i want to let it open until i write a special word.


Solution

  • Here's a silly example:

    Sub Main()
        Dim password As String = "007"
    
        Dim response As String
        Do
            Console.Write("Password: ")
            response = Console.ReadLine
            If response <> password Then
                Console.WriteLine("Incorrect Password!")
            End If
        Loop While response <> password
    
        Console.WriteLine("Welcome James Bond!")
        Console.Write("Press [Enter] to proceed...")
        Console.ReadLine()
    End Sub