2017-10-09 71 views
0

我想保存If語句的輸出/用戶輸入,但代碼中的變量似乎不適用於我需要的指定行。保存某個If語句的輸出/用戶輸入(VB)

Dim timer As Integer = 0 
Dim answer As String = 0 
Do 
    timer = timer + 1 
    Thread.Sleep(1000) 
    If Console.KeyAvailable Then 
     If Console.ReadKey(True).KeyChar = "q" Then Exit Do 
    End If 
Loop 
Console.WriteLine(timer) 
Console.Read() 

我需要用戶在.KeyChar語句後輸入的內容。任何幫助?

回答

0

鴻溝,在兩個或多個排隊,分配到Console.ReadLine給一個變量:

Dim userKey as ConsoleKeyInfo 
... 
If Console.KeyAvailable Then 
    userKey = Console.ReadKey() 
    If userKey.Key.ToString = "q" Then Exit Do 
End If 
... 

看看MSDN - ReadKey獲取更詳細的信息