Ich habe diesen Code gesetzt, um zwei Operatoren zu stoppen, arbeitet an +, *,/aber funktioniert nicht auf "-", wenn versucht, (-3-3) Sie drücken müssen die gleiche Taste ein anderer Bediener erlaubtRechner Microsoft Visual Studio 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
können Sie den Code eingeben für die mehr Sinn Danke für die Antwort – Rakan
Ich bin nicht gut in VB machen bitte, aber ich werde versuchen, –
Ich denke, es sollte genug sein 'Wenn txtTyped.Text hinzufügen ==" "Return" am Anfang von "btnMinus_Click" –