Basic Calculator
Designing
Watch the video above on YouTube.
For programming use the code below:
Dim Firstnum As Decimal
Dim secondnum As Decimal
Dim Operations As Integer
Dim Operator_selctor As Boolean = False
Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
Application.Exit()
End Sub
Private Sub BtnClear_Click(sender As Object, e As EventArgs) Handles BtnClear.Click
TextBox1.Text = "0"
End Sub
Private Sub BtnDivide_Click(sender As Object, e As EventArgs) Handles BtnDivide.Click
Firstnum = TextBox1.Text
TextBox1.Text = ""
Operator_selctor = True
Operations = 4 ' = /
End Sub
Private Sub BtnMultiply_Click(sender As Object, e As EventArgs) Handles BtnMultiply.Click
Firstnum = TextBox1.Text
TextBox1.Text = ""
Operator_selctor = True
Operations = 3 ' = *
End Sub
Private Sub BtnSubstract_Click(sender As Object, e As EventArgs) Handles BtnSubstract.Click
Firstnum = TextBox1.Text
TextBox1.Text = ""
Operator_selctor = True
Operations = 2 ' = -
End Sub
Private Sub BtnAdd_Click(sender As Object, e As EventArgs) Handles BtnAdd.Click
Firstnum = TextBox1.Text
TextBox1.Text = ""
Operator_selctor = True
Operations = 1 ' = +
End Sub
Private Sub BtnSyntax_Click(sender As Object, e As EventArgs) Handles BtnSyntax.Click
If Operator_selctor = True Then
secondnum = TextBox1.Text
If Operations = 1 Then
TextBox1.Text = Firstnum + secondnum
ElseIf Operations = 2 Then
TextBox1.Text = Firstnum - secondnum
ElseIf Operations = 3 Then
TextBox1.Text = Firstnum * secondnum
Else
If secondnum = 0 Then
TextBox1.Text = "Error!"
Else
TextBox1.Text = Firstnum / secondnum
End If
End If
Operator_selctor = False
End If
End Sub
Private Sub BtnDot_Click(sender As Object, e As EventArgs) Handles BtnDot.Click
If Not (TextBox1.Text.Contains(".")) Then
TextBox1.Text += "."
End If
End Sub
Private Sub Btn0_Click(sender As Object, e As EventArgs) Handles Btn0.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "0"
End If
End Sub
Private Sub Btn1_Click(sender As Object, e As EventArgs) Handles Btn1.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "1"
Else
TextBox1.Text = "1"
End If
End Sub
Private Sub Btn2_Click(sender As Object, e As EventArgs) Handles Btn2.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "2"
Else
TextBox1.Text = "2"
End If
End Sub
Private Sub Btn3_Click(sender As Object, e As EventArgs) Handles Btn3.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "3"
Else
TextBox1.Text = "3"
End If
End Sub
Private Sub Btn4_Click(sender As Object, e As EventArgs) Handles Btn4.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "4"
Else
TextBox1.Text = "4"
End If
End Sub
Private Sub Btn5_Click(sender As Object, e As EventArgs) Handles Btn5.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "5"
Else
TextBox1.Text = "5"
End If
End Sub
Private Sub Btn6_Click(sender As Object, e As EventArgs) Handles Btn6.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "6"
Else
TextBox1.Text = "6"
End If
End Sub
Private Sub Btn7_Click(sender As Object, e As EventArgs) Handles Btn7.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "7"
Else
TextBox1.Text = "7"
End If
End Sub
Private Sub Btn8_Click(sender As Object, e As EventArgs) Handles Btn8.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "8"
Else
TextBox1.Text = "8"
End If
End Sub
Private Sub Btn9_Click(sender As Object, e As EventArgs) Handles Btn9.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "9"
Else
TextBox1.Text = "9"
End If
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
BtnClear.PerformClick()
End Sub
Private Sub PictureBox1_MouseHover(sender As Object, e As EventArgs) Handles PictureBox1.MouseHover
PictureBox1.BackColor = Color.Red
End Sub
Private Sub PictureBox1_MouseLeave(sender As Object, e As EventArgs) Handles PictureBox1.MouseLeave
PictureBox1.BackColor = Color.WhiteSmoke
End Sub
End Class