0
我已经把这段代码停止插入两个操作符,正在+,*,/但 不工作的“ - ”,当试图把(-3-3)你必须按等于按钮来允许其他运营商被插入计算器微软视觉工作室2010
Public Class Form1
'Global variable to check if equals has been pressed
Dim is_equals_pressed As Boolean = False
Dim operator_count As Integer = 0
Dim allowed_input As Boolean = False
Private Sub btnMinus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMinus.Click
operator_count += 1
allowed_input = Check_Values()
If allowed_input <> False Then
If txtAnswer.Text = "" Then
If Check_Values() = False Then
txtAnswer.Focus()
Exit Sub
End If
End If
If is_equals_pressed = True Then
txtTyped.Text = txtAnswer.Text & "-"
txtAnswer.Text = "" 'clear the text box
is_equals_pressed = False
Else
txtTyped.Text += txtAnswer.Text & "-"
txtAnswer.Text = "" 'clear the text box
txtAnswer.Focus()
End If
End If
End Sub
Private Sub btnMultiply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMultiply.Click
operator_count += 1
allowed_input = Check_Values()
If allowed_input <> False Then
If txtAnswer.Text = "" Then
If Check_Values() = False Then
txtAnswer.Focus()
Exit Sub
End If
End If
If is_equals_pressed = True Then
txtTyped.Text = txtAnswer.Text & "*"
txtAnswer.Text = "" 'clear the text box
is_equals_pressed = False
Else
txtTyped.Text += txtAnswer.Text & "*"
txtAnswer.Text = "" 'clear the text box
txtAnswer.Focus()
End If
End If
End Sub
Private Sub btnEquals_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEquals.Click
Dim equation As String
operator_count = 0
'Cos, Sin, Tan
Dim num1 As String
'End
Dim i As Integer = 1
txtTyped.Text += txtAnswer.Text
'Capture value for Cos, Sin, Tan calculation
num1 = txtAnswer.Text
'End
txtAnswer.Text = ("") 'Clear the text box
equation = txtTyped.Text
'Check if equals has been pressed
is_equals_pressed = True
'Check for +, -, =,/simbol in string
For i = 1 To equation.Length - 1
If equation(i) = "+" Then
addNumbers(equation)
ElseIf equation(i) = "-" Then
subtrtactNumbers(equation)
ElseIf equation(i) = "*" Then
multiplyNumbers(equation)
ElseIf equation(i) = "/" Then
divideNumbers(equation)
ElseIf equation(i) = "^" Then
exponentNumber(equation)
ElseIf equation(i) = "%" Then
modulusNumbers(equation)
ElseIf equation.Contains("1/") Then
inverseNumbers(equation)
'We do this calculation in btnCos_Click
ElseIf equation.Contains("Cos") Then
ElseIf equation.Contains("Sin") Then
ElseIf equation.Contains("Tan") Then
End If
Next
txtAnswer.Select(txtAnswer.Text.Length, 0)
End Sub
Private Function Check_Values() As Boolean
If operator_count > 1 Then
allowed_input = False
Else
allowed_input = True
End If
Check_Values = allowed_input
End Function
你可以输入代码,请更有意义感谢您的回复 – Rakan
我不擅长VB,但我会尝试 –
我认为这应该足以添加'如果txtTyped.Text ==“ “然后返回'在'btnMinus_Click'开头 –