Vb.net simple calculator implementation
rendering
1 First we need to put the controls in place.
2 Handle buttons 0 to 9
'button 0 ~ 9
Private Sub Button1_Click(ByVal sender As System.Object.ByVal e As System.EventArgs) Handles Button1.Click
If stat = 1 Then
TextBox1.Text = 0
stat = 0
End If
If TextBox1.Text = "0" Then
TextBox1.Text = "1"
Else
TextBox1.Text = TextBox1.Text + "1"
End If
End Sub
Copy the code
3 Handle the events of the add, subtract, multiply and divide buttons
'buttons add, subtract, multiply and divide
Private Sub Button10_Click(ByVal sender As System.Object.ByVal e As System.EventArgs) Handles Button10.Click
sign = "+"
one = TextBox1.Text
TextBox1.Text = 0
End Sub
Private Sub Button11_Click(ByVal sender As System.Object.ByVal e As System.EventArgs) Handles Button11.Click
sign = "-"
one = TextBox1.Text
TextBox1.Text = 0
End Sub
Private Sub Button12_Click(ByVal sender As System.Object.ByVal e As System.EventArgs) Handles Button12.Click
sign = "*"
one = TextBox1.Text
TextBox1.Text = 0
End Sub
Private Sub Button13_Click(ByVal sender As System.Object.ByVal e As System.EventArgs) Handles Button13.Click
sign = "/"
one = TextBox1.Text
TextBox1.Text = 0
End Sub
Copy the code
4 Handle the = button event
'button equals sign
Private Sub Button16_Click(ByVal sender As System.Object.ByVal e As System.EventArgs) Handles Button16.Click
two = TextBox1.Text
If sign = "+" Then
add()
End If
If sign = "-" Then
minus()
End If
If sign = "*" Then
multiply()
End If
If sign = "/" Then
divide()
End If
End Sub
Copy the code