我正在編寫一個簡單的Visual Basic四功能計算器(加,減,乘,除)應用程序,我希望在按下操作符時顯示中間結果。如何在VB計算器程序中顯示中間結果
,我已創建的視窗表單包含按鈕,因此輸入僅通過在GUI上的鼠標點擊(無鍵盤輸入)
如在要求定義需要一個完整的「問題」將根據輸入以下順序規則:
- 一個數字,隨後
- 操作者鍵,接着
- 另一個號碼,然後按
- (可選)重複步驟2(按操作員時顯示中間結果)或等號按鈕。
據我所知,需要在運營商click_events中進行更改才能滿足此要求,但我不知道該怎麼做。
這裏是在添加代碼,減,乘,除和等於按鈕
Dim txtNumber As String
Dim variable1 As Decimal
Dim variable2 As Decimal
Dim answerResult As Decimal
Dim arithmeticProcess As String
Private Sub btnAdd_Click(sender As System.Object, e As System.EventArgs) Handles btnAdd.Click
If answerResult <> 0 Then
answerResult = variable1 + variable2
variable1 = CDec(lblDisplay.Text)
lblDisplay.Text = ""
arithmeticProcess = "+"
Else
variable1 = CDec(lblDisplay.Text)
lblDisplay.Text = ""
arithmeticProcess = "+"
End If
End Sub
Private Sub btnSubtract_Click(sender As System.Object, e As System.EventArgs) Handles btnSubtract.Click
variable1 = CDec(lblDisplay.Text)
lblDisplay.Text = ""
arithmeticProcess = "-"
End Sub
Private Sub btnMultiply_Click(sender As System.Object, e As System.EventArgs) Handles btnMultiply.Click
variable1 = CDec(lblDisplay.Text)
lblDisplay.Text = ""
arithmeticProcess = "*"
End Sub
Private Sub btnDivide_Click(sender As System.Object, e As System.EventArgs) Handles btnDivide.Click
variable1 = CDec(lblDisplay.Text)
lblDisplay.Text = ""
arithmeticProcess = "/"
End Sub
Private Sub btnEqual_Click(sender As System.Object, e As System.EventArgs) Handles btnEqual.Click
variable2 = lblDisplay.Text
If arithmeticProcess = "+" Then
answerResult = variable1 + variable2
ElseIf arithmeticProcess = "-" Then
answerResult = variable1 - variable2
ElseIf arithmeticProcess = "*" Then
answerResult = variable1 * variable2
Else
answerResult = variable1/variable2
End If
answerResult = Math.Round(answerResult, 9)
Select Case answerResult
Case Is > 4000000000
MessageBox.Show("The answer is too large to be displayed.")
variable1 = 0
variable2 = 0
lblDisplay.Text = ""
Case Is < -4000000000
MessageBox.Show("The answer is too small to be displayed.")
variable1 = 0
variable2 = 0
lblDisplay.Text = ""
Case Else
lblDisplay.Text = CStr(answerResult)
End Select
End Sub
'如果lblDisplay.Text = 「0」 然後 lblDisplay.Text = 「」 結束如果 txtNumber = lblDisplay.Text 如果txtNumber.Contains( 「」)。然後 如果txtNumber.Length> 10然後 MessageBox.Show(「顯示須顯示不超過10個數字。」) 退出小組 結束如果 elseif的txtNumber.Length> 9然後 MessageBox.Show(「顯示須顯示不超過10個數字。」) 退出Sub End If txtNumber + =「1」 lblDisplay.Text = txtNumber' – Theo 2014-10-07 12:27:17
這是我的按鈕0-9的代碼,但我該如何流程圖應用程序?要做這些的步驟是什麼? – Theo 2014-10-07 12:28:04