Option Explicit
Dim mem As Double, ans As Double, desi As Boolean, n As Double
Dim no1 As Double, no2 As Double, fact As Integer, i As Integer
Dim operation As Boolean, op As String, res As Double, index As Integer
Private Sub cmd1divide_Click()
n = Val(Label1.Caption)
If n = 0 Then
MsgBox "Divide by zero error"
Else
Label1.Caption = 1 / Val(Label1.Caption)
End If
End Sub
Private Sub cmdbackspace_Click()
Label1.Caption = Left(Label1.Caption, Len(Label1) - 1)
End Sub
Private Sub cmdclear_Click()
Label1.Caption = ""
End Sub
Private Sub cmdcos_Click()
ans = Label1.Caption
Label1.Caption = Round(Cos(ans * 3.142878669 / 180), 5)
End Sub
Private Sub cmdcube_Click()
Label1.Caption = Val(Label1.Caption) ^ 3
End Sub
Private Sub cmddot_Click()
If desi = False Then
Label1.Caption = Label1.Caption + cmddot.Caption
End If
desi = True
End Sub
Private Sub cmdequ_Click()
If index <> 0 Then
If operation = False Then
no1 = Val(Label1.Caption)
Else
no2 = Val(Label1.Caption)
If op = "/" Then
res = no1 / no2
ElseIf op = "*" Then
res = no1 * no2
ElseIf op = "-" Then
res = no1 - no2
ElseIf op = "+" Then
res = no1 + no2
ElseIf op = "%" Then
res = no1 Mod no2
ElseIf op = "X^Y" Then
res = no1 ^ no2
End If
no1 = res
End If
operation = True
Select Case index
Case 1
op = "/"
Case 2
op = "*"
Case 3
op = "-"
Case 4
op = "+"
Case 5
op = "%"
Case 6
op = "^"
End Select
Label1.Caption = ""
Else
If operation = True Then
no2 = Val(Label1.Caption)
If op = "/" Then
res = no1 / no2
ElseIf op = "*" Then
res = no1 * no2
ElseIf op = "-" Then
res = no1 - no2
ElseIf op = "+" Then
res = no1 + no2
ElseIf op = "%" Then
res = no1 Mod no2
ElseIf op = "X^Y" Then
res = no1 ^ no2
End If
Label1.Caption = res
Else
Label1.Caption = no1
End If
operation = False
End If
End Sub
Private Sub cmdexp_Click()
Label1.Caption = Exp(Val(Label1.Caption))
End Sub
Private Sub cmdfact_Click()
no1 = Val(Label1.Caption)
fact = 1
For i = 0 To no1
fact = fact * i
Next i
Label1.Caption = fact
End Sub
Private Sub cmdlog_Click()
Label1.Caption = Log(Val(Label1.Caption)) / Log(10)
End Sub
Private Sub cmdlogin_Click()
Label1.Caption = Log(Val(Label1.Caption))
End Sub
Private Sub cmdmc_Click()
mem = 0
End Sub
Private Sub cmdminus_Click()
mem = mem - Val(Label1.Caption)
End Sub
Private Sub cmdmr_Click()
Label1.Caption = mem
End Sub
Private Sub cmdms_Click()
mem = Val(Label1.Caption)
End Sub
Private Sub cmdoff_Click()
Dim i As Integer
i = index
For i = 0 To Command6.Count - 1
Command6(i).Enabled = False
Next
For i = 0 To opr.Count - 1
opr(i).Enabled = False
Next
cmdmc.Enabled = False
cmdmr.Enabled = False
cmdms.Enabled = False
cmdplus.Enabled = False
cmdminus.Enabled = False
cmdsqrt.Enabled = False
cmdlog.Enabled = False
cmd1divide.Enabled = False
cmdsin.Enabled = False
cmdcos.Enabled = False
cmdtan.Enabled = False
cmdplusminus.Enabled = False
cmdclear.Enabled = False
cmdpi.Enabled = False
cmdexp.Enabled = False
cmdlogin.Enabled = False
cmdfact.Enabled = False
cmdbackspace.Enabled = False
cmdsqr.Enabled = False
cmdcube.Enabled = False
cmdten.Enabled = False
cmddot.Enabled = False
cmdon.Enabled = True
End Sub
Private Sub cmdon_Click()
Dim i As Integer
i = index
For i = 0 To Command6.Count - 1
Command6(i).Enabled = True
Next
For i = 0 To opr.Count - 1
opr(i).Enabled = True
Next
cmdmc.Enabled = True
cmdmr.Enabled = True
cmdms.Enabled = True
cmdplus.Enabled = True
cmdminus.Enabled = True
cmdsqrt.Enabled = True
cmdlog.Enabled = True
cmd1divide.Enabled = True
cmdsin.Enabled = True
cmdcos.Enabled = True
cmdtan.Enabled = True
cmdplusminus.Enabled = True
cmdclear.Enabled = True
cmdpi.Enabled = True
cmdexp.Enabled = True
cmdlogin.Enabled = True
cmdfact.Enabled = True
cmdbackspace.Enabled = True
cmdsqr.Enabled = True
cmdcube.Enabled = True
cmdten.Enabled = True
cmddot.Enabled = True
cmdoff.Enabled = True
End Sub
Private Sub cmdpi_Click()
Label1.Caption = 3.142878669
End Sub
Private Sub cmdplus_Click()
mem = Val(Label1.Caption) + mem
End Sub
Private Sub cmdplusminus_Click()
Label1.Caption = -Val(Label1.Caption)
End Sub
Private Sub cmdsin_Click()
ans = Val(Label1.Caption)
Label1.Caption = Round(Sin(ans * 3.142878669 / 180), 5)
End Sub
Private Sub cmdsqr_Click()
Label1.Caption = Val(Label1.Caption) ^ 2
End Sub
Private Sub cmdsqrt_Click()
Label1.Caption = Sqrt(Label1.Caption)
End Sub
Private Sub cmdtan_Click()
ans = Label1.Caption
Label1.Caption = Round(Tan(ans * 3.142878669 / 180), 5)
End Sub
Private Sub cmdten_Click()
Label1.Caption = 10 ^ Val(Label1.Caption)
End Sub
Private Sub Command6_Click(index As Integer)
Label1.Caption = Label1.Caption + Command6(index).Caption
End Sub
Private Sub Form_Load()
Call cmdoff_Click
desi = False
operation = False
End Sub
Private Sub opr_Click(index As Integer)
i = Label1.Caption
op = opr(index).Caption
Label1.Caption = ""
End Sub
Please recover it.This code is not performing properly,not giving answer as clicking on equal to("=") button.Please help me.