VBA Calculator

You can download VBA Calculator from here

Calculator in VBA
Public Calval As String
Private Sub btndot_Click()
    If txtMainDis <> 0 Then
        txtMainDis = txtMainDis + btndot.Caption
    End If
End Sub

Private Sub btn0_Click()
    If txtMainDis = 0 Then
        txtMainDis = btn0.Caption
    Else
        txtMainDis = txtMainDis + btn0.Caption
    End If
End Sub

Private Sub btn1_Click()
    If txtMainDis = 0 Then
        txtMainDis = btn1.Caption
    Else
        txtMainDis = txtMainDis + btn1.Caption
    End If
End Sub

Private Sub btn2_Click()
    If txtMainDis = 0 Then
        txtMainDis = btn2.Caption
    Else
        txtMainDis = txtMainDis + btn2.Caption
    End If
End Sub

Private Sub btn3_Click()
    If txtMainDis = 0 Then
        txtMainDis = btn3.Caption
    Else
        txtMainDis = txtMainDis + btn3.Caption
    End If
End Sub

Private Sub btn4_Click()
    If txtMainDis = 0 Then
        txtMainDis = btn4.Caption
    Else
        txtMainDis = txtMainDis + btn4.Caption
    End If
End Sub

Private Sub btn5_Click()
    If txtMainDis = 0 Then
        txtMainDis = btn5.Caption
    Else
        txtMainDis = txtMainDis + btn5.Caption
    End If
End Sub

Private Sub btn6_Click()
    If txtMainDis = 0 Then
        txtMainDis = btn6.Caption
    Else
        txtMainDis = txtMainDis + btn6.Caption
    End If
End Sub

Private Sub btn7_Click()
    If txtMainDis = 0 Then
        txtMainDis = btn7.Caption
    Else
        txtMainDis = txtMainDis + btn7.Caption
    End If
End Sub

Private Sub btn8_Click()
    If txtMainDis = 0 Then
        txtMainDis = btn8.Caption
    Else
        txtMainDis = txtMainDis + btn8.Caption
    End If
End Sub

Private Sub btn9_Click()
    If txtMainDis = 0 Then
        txtMainDis = btn9.Caption
    Else
        txtMainDis = txtMainDis + btn9.Caption
    End If
End Sub
'Code for Action  ADDITION    DIVISION  MULTIPLICATION  MINUS
Private Sub btnadd_Click()
    If txtMainDis <> 0 Then
        txtDisplay = txtMainDis
        txtMainDis = 0
        Calval = "Add"
    End If
End Sub
Private Sub btndiv_Click()
    If txtMainDis <> 0 Then
        txtDisplay = txtMainDis
        txtMainDis = 0
        Calval = "Div"
    End If
End Sub

Private Sub btnmin_Click()
    If txtMainDis <> 0 Then
        txtDisplay = txtMainDis
        txtMainDis = 0
        Calval = "Min"
    End If
End Sub

Private Sub btnmulti_Click()
    If txtMainDis <> 0 Then
        txtDisplay = txtMainDis
        txtMainDis = 0
        Calval = "Multi"
    End If
End Sub


Private Sub btnequal_Click()
    Dim fNum As Double
    Dim sNum As Double

    If Calval <> "" And txtDisplay <> "" Then
        fNum = Val(txtDisplay)
        sNum = Val(txtMainDis)
        If Calval = "Add" Then
            txtMainDis = fNum + sNum
        ElseIf Calval = "Min" Then
            txtMainDis = fNum - sNum
        ElseIf Calval = "Multi" Then
            txtMainDis = fNum * sNum
        ElseIf Calval = "Div" Then
            txtMainDis = fNum / sNum
        End If
    End If

End Sub

Private Sub btnclr_Click()
    txtDisplay = ""
    txtMainDis = 0
End Sub


Private Sub btnoff_Click()
    txtMainDis = ""
    txtDisplay = ""
End Sub

Private Sub UserForm_Initialize()
    txtDisplay.MaxLength = 10
    txtMainDis.MaxLength = 10
End Sub

Total Page Visits: 3963 - Today Page Visits: 41