0
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.

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by BitBlt
0

As near as I can tell, the problem is that the variable "index" defined at the module level is never set to an explicit value. You reference "index" on line 40 above, testing it for a value not equal zero. Fair enough, but it never gets set anywhere else to anything BUT zero so the conditional falls through to the "else" condition. First thing that happens there is you test the boolean variable "operation" for TRUE...which only gets set in the part of the conditional that will never execute.

My suggestion is to:
1. Use some other variable name, because there is a local event parameter in 2 separate event procedures with the same name...very confusing.
2. Determine how the value of "index" is supposed to be set, as in "in which event procedure" and finally
3. Double check all the places you use the variable "i" because you have used it as both a local and a module-level variable, and I think in procedures cmdoff_click and cmdon_click, you're mixing up what it should be used for and making a mess.
4. Also, double check procedure cmdopr_click because that's where you set module-level "i" and causes other havoc.
5. Check what happens when you finally get the conditional in line 40 to work. You seem to have some fall-through logic that you want to bypass in the top part of the conditional, and you never put the result back into the label caption.

Hope these hints help you. Good luck!

Edited by BitBlt

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.