Calculator - Visual Basic 2008 / 2010
Page 4
The Zero Button: Double click on the zero button and add the following highlighted code:
Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
If Button1.Text = Label1.Text Then
Button1.Text = "0."
ElseIf Button1.Text = "0." Then
Button1.Text = "0."
ElseIf Button1.Text = "0" Then
Button1.Text = "0."
ElseIf Button1.Text = Label3.Text Then
Button1.Text = "0."
Else
Button1.Text = Button1.Text & "0"
End If
End Sub
The Decimal Button:
Double click on the decimal button and add the following highlighted code:
Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
If Button1.Text = "0." Then
Button1.Text = "."
ElseIf Button1.Text = Label3.Text Then
Button1.Text = "."
ElseIf Button1.Text = Label1.Text Then
Button1.Text = "."
Else
If Button1.Text.Contains(".") Then
Else
Button1.Text = Button1.Text & "."
End If
End If
End Sub
The One Button:
Double click on the one button and add the following highlighted code:
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
If Button1.Text = Label1.Text Then
Button1.Text = "1"
ElseIf Button1.Text = "0." Then
Button1.Text = "1"
ElseIf Button1.Text = Label3.Text Then
Button1.Text = "1"
Else
Button1.Text = Button1.Text & "1"
End If
End Sub
The Two Button:
Double click on the two button and add the following highlighted code:
Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
If Button1.Text = Label1.Text Then
Button1.Text = "2"
ElseIf Button1.Text = "0." Then
Button1.Text = "2"
ElseIf Button1.Text = Label3.Text Then
Button1.Text = "2"
Else
Button1.Text = Button1.Text & "2"
End If
End Sub
The Three Button:
Double click on the three button and add the following highlighted code:
Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
If Button1.Text = Label1.Text Then
Button1.Text = "3"
ElseIf Button1.Text = "0." Then
Button1.Text = "3"
ElseIf Button1.Text = Label3.Text Then
Button1.Text = "3"
Else
Button1.Text = Button1.Text & "3"
End If
End Sub
The Four Button:
Double click on the four button and add the following highlighted code:
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
If Button1.Text = Label1.Text Then
Button1.Text = "4"
ElseIf Button1.Text = "0." Then
Button1.Text = "4"
ElseIf Button1.Text = Label3.Text Then
Button1.Text = "4"
Else
Button1.Text = Button1.Text & "4"
End If
End Sub
The Five Button:
Double click on the five button and add the following highlighted code:
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
If Button1.Text = Label1.Text Then
Button1.Text = "5"
ElseIf Button1.Text = "0." Then
Button1.Text = "5"
ElseIf Button1.Text = Label3.Text Then
Button1.Text = "5"
Else
Button1.Text = Button1.Text & "5"
End If
End Sub
The Six Button:
Double click on the six button and add the following highlighted code:
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
If Button1.Text = Label1.Text Then
Button1.Text = "6"
ElseIf Button1.Text = "0." Then
Button1.Text = "6"
ElseIf Button1.Text = Label3.Text Then
Button1.Text = "6"
Else
Button1.Text = Button1.Text & "6"
End If
End Sub
The Seven Button:
Double click on the seven button and add the following highlighted code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If Button1.Text = Label1.Text Then
Button1.Text = "7"
ElseIf Button1.Text = "0." Then
Button1.Text = "7"
ElseIf Button1.Text = Label3.Text Then
Button1.Text = "7"
Else
Button1.Text = Button1.Text & "7"
End If
End Sub
The Eight Button:
Double click on the eight button and add the following highlighted code:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If Button1.Text = Label1.Text Then
Button1.Text = "8"
ElseIf Button1.Text = "0." Then
Button1.Text = "8"
ElseIf Button1.Text = Label3.Text Then
Button1.Text = "8"
Else
Button1.Text = Button1.Text & "8"
End If
End Sub
The Nine Button:
Double click on the nine button and add the following highlighted code:
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If Button1.Text = Label1.Text Then
Button1.Text = "9"
ElseIf Button1.Text = "0." Then
Button1.Text = "9"
ElseIf Button1.Text = Label3.Text Then
Button1.Text = "9"
Else
Button1.Text = Button1.Text & "9"
End If
End Sub
The calculator is ready now and should work fine.
If your calculator is working fine, you can publish it:
Comments
Post a Comment