0
我在Visual Basic中,我通過一些代碼段我老師寫讀書,他有這chunck代碼:的Visual Basic將
Private Sub btnDividing_Click(sender As Object, e As EventArgs) Handles btnDividing.Click
Dim number As Integer = InputBox("Divide number by 2:")
Dim result As Integer = 0
Do While (number <> 0)
result += 1
number = number - 2
Loop
MsgBox("The result is: " & result, MsgBoxStyle.Exclamation)
End Sub
所以我的老師鍵入結果+ = 1和數=號-2我真的不明白那部分,所以我試圖將其更改爲簡化IT:
Dim number As Integer = InputBox("Divide number by 2:")
Dim result As Integer = 0
Do While (number <> 0)
result = number/2
Loop
MsgBox("The result is: " & result, MsgBoxStyle.Exclamation)
End Sub
但它一直在我點擊「OK」
012凍結有什麼建議嗎?
注意:這不是VBA,所以我編輯標籤來說它是VB.Net。 (我相當肯定這將是正確的。) – YowE3K
作爲一個方面說明,我會推薦Option Strict https://stackoverflow.com/documentation/vb.net/4022/option-strict和Dim code = Val(InputBox (「Divide number by 2:」))'作爲InputBox返回一個字符串 – Slai
有一個巨大的假設,數字將是偶數。如果不是,它將是一個循環。也許老師的意思是> 0而不是<> 0.讓我們希望如此。 – dbasnett