2015-10-16 53 views
0

我是新來的Visual Basic和希望,如果他們按重新啓動控制檯程序,如果用戶輸入「1」,退出任何其他鍵重新啓動控制檯程序1個鍵或其他所有退出

我曾用「 Console.ReadLine「與If語句結合使用,但麻煩在於我不希望他們在輸入後不得不按Enter鍵。

任何幫助,將不勝感激和抱歉如果這是一個基本的問題(沒有雙關語意)

+1

請顯示您已經嘗試過的代碼。 –

+0

愚蠢的問題,但我是否打破新線?當我按下輸入它的帖子評論:( – ronlaboa

+0

@ronlaboa你不能在評論中使用換行符。 –

回答

1

而不是使用的ReadLine,你可以使用ReadKey。這不會等待輸入。

'Clear any keys from the input buffer 
While Console.ReadKey(True) 
End While 

Dim MyKey = Console.ReadKey(True) 
If MyKey.KeyChar = "1"c Then 
    'We can act on the key since they pressed 1 (let the main application repeat) 
Else 
    'They pressed something else, we want to exit the application 
End If 
+0

非常感謝你,它的「MyKey.KeyChar我不知道:D – ronlaboa

相關問題