Ask Experts Questions for FREE Help !
Ask
    techyayush's Avatar
    techyayush Posts: 1, Reputation: 1
    New Member
     
    #1

    Jul 12, 2008, 11:04 AM
    unable to give a finish to a calculator
    Hi I am ayush

    I have made a calculator that performs every arithmetic operation but the problem is that suppose I want to add 1+1+1. so I stored the value of first1 in x(variable) then I click on + then added another 1 in variable in y then when I again hit plus button the textbox should show value 2 but it doesn't then when I again click on 1 and press = then it shows 3.But I want to show that as soon as I second time hit plus then answer should be on textbox.


    To make this calculator I've assigned value of "a" for every arithmetic operation and using these values I come to the result. Every time the result shown is correct but not showing of result as soon as arithmetic operator's button is a big problem.. So help me
    znet2705zc's Avatar
    znet2705zc Posts: 34, Reputation: 1
    Junior Member
     
    #2

    Jul 27, 2008, 08:09 AM
    Look at this code. (a sample of calculator)

    Option Explicit
    Dim strPreviousValue As String
    Dim strOperator As String
    Dim blnDot As Boolean
    Dim strMemory As String
    Dim blnDisplay As Boolean
    Dim strAuthor As String
    Private Sub Form_Load()
    lblDisplay.Caption = "0"
    strPreviousValue = ""
    strMemory = "
    strMemory = "
    strOperator = ""
    blnDot = False
    blnDisplay = True

    End Sub
    Private Sub cmdNumber_Click(Index As Integer)
    If blnDisplay = True Then
    If blnDot = False And lblDisplay.Caption = "
    strOperator = " Then
    lblDisplay.Caption = ""
    blnDot = False
    blnDisplay = True

    End Sub
    Private Sub cmdNumber_Click(Index As Integer)
    If blnDisplay = True Then
    If blnDot = False And lblDisplay.Caption = "." Then
    lblDisplay.Caption = "0."
    blnDisplay = True
    blnDot = True
    End If
    End Sub
    Private Sub cmdCE_Click()
    If Timer1.Enabled = True Then Timer1.Enabled = False
    blnDot = False
    lblDisplay.Caption = "
    End If
    lblDisplay.Caption = lblDisplay.Caption + cmdNumber(Index).Caption
    Else
    strPreviousValue = lblDisplay.Caption
    lblDisplay.Caption = cmdNumber(Index).Caption
    blnDisplay = True
    End If
    End Sub
    Private Sub cmdDot_Click()
    If blnDisplay = True Then
    If blnDot = False Then
    blnDot = True
    lblDisplay.Caption = lblDisplay.Caption + "
    strOperator = ""
    strPreviousValue = "
    End If
    Exit Sub
    End If
    If blnDisplay = False And blnDot = False Then
    lblDisplay.Caption = "
    'strMemory = "
    blnDisplay = True
    blnDot = True
    End If
    End Sub
    Private Sub cmdCE_Click()
    If Timer1.Enabled = True Then Timer1.Enabled = False
    blnDot = False
    lblDisplay.Caption = "
    End Sub
    Private Sub cmdOperator_Click(Index As Integer)
    blnDot = False
    blnDisplay = False
    If Len(strOperator) = 1 Then
    Call math
    strOperator = cmdOperator(Index).Caption
    Else
    strOperator = cmdOperator(Index).Caption
    strPreviousValue = lblDisplay.Caption
    End If
    End Sub
    Private Function math()
    On Error Go to errorHandler
    Select Case strOperator
    Case "+"
    strOperator = "-"
    strPreviousValue = "x"
    'strMemory = "/"
    End Sub
    Private Sub cmdOperator_Click(Index As Integer)
    blnDot = False
    blnDisplay = False
    If Len(strOperator) = 1 Then
    Call math
    strOperator = cmdOperator(Index).Caption
    Else
    strOperator = cmdOperator(Index).Caption
    strPreviousValue = lblDisplay.Caption
    End If
    End Sub
    Private Function math()
    On Error GoTo errorHandler
    Select Case strOperator
    Case "Error "
    lblDisplay.Caption = Val(lblDisplay.Caption) + Val(strPreviousValue)
    Case ""
    strPreviousValue = "
    lblDisplay.Caption = Val(strPreviousValue) - Val(lblDisplay.Caption)
    Case "
    blnDot = False
    blnDisplay = False
    End Function
    Private Sub cmdIsEqualTo_Click()
    Call math
    strOperator = ""
    lblDisplay.Caption = Val(lblDisplay.Caption) * Val(strPreviousValue)
    Case "M+"
    lblDisplay.Caption = Val(strPreviousValue) / Val(lblDisplay.Caption)
    End Select
    Exit Function
    errorHandler:
    lblDisplay.Caption = "M-"
    strOperator = "MR"
    strPreviousValue = "MC"
    strMemory = "
    blnDot = False
    blnDisplay = False
    End Function
    Private Sub cmdIsEqualTo_Click()
    Call math
    strOperator = "
    lblDisplay.Caption = "
    If Len(lblDisplay.Caption) <= 19 Then
    lblDisplay.FontSize = 15
    Else
    lblDisplay.FontSize = 10
    End If
    End Sub
    Private Sub cmdPlusOrMinus_Click()
    lblDisplay.Caption = Val(lblDisplay.Caption) - (Val(lblDisplay.Caption) + Val(lblDisplay.Caption))
    End Sub
    Private Sub cmdSqrt_Click()
    lblDisplay.Caption = Sqr(Val(lblDisplay.Caption))
    End Sub
    Private Sub cmdMemory_Click(Index As Integer)
    If Timer1.Enabled = False Then
    Select Case cmdMemory(Index).Caption
    Case "
    End Select
    End If
    End Sub
    Private Sub Timer1_Timer()
    strAuthor = Mid$(strAuthor, 2, Len(strAuthor) - 1) + Left(strAuthor, 1)
    lblDisplay.Caption = Left(strAuthor, 18)
    End Sub
    KISS's Avatar
    KISS Posts: 12,510, Reputation: 839
    Uber Member
     
    #3

    Jul 27, 2008, 01:12 PM
    It's so much easier doing the calculations using RPN (Reverse Polish Notation) and doing a Algebraic to RPN conversion

    1 1 1 + + or 1 1 + 1 + is so much easier to do than 1+1+1.

    Been there, done that.

    In the second example, the code becomes:
    Push 1
    Push 1
    Add
    Push 1
    Add

    Use a stack at least 4 deep and an operator operates on the last two elements of the stack.

    The algebraic BS has to deal with operator precedence and parenthsis.

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Vb 6.0 calculator [ 2 Answers ]

Please help me! On my prject , I need a source code of a vb 6.0 calculator please help. Tnx

It's not where you start, it's where you finish and I'm going to finish on top. [ 3 Answers ]

Can anyone help me find the name of the song and lyrics to the song that has the line... "It's not where you start, it's where you finish and I'm going to finish on top." It came from a show, possibly Barnum? Thanks David

TI-84 Plus Calculator [ 1 Answers ]

This is sort of a math question and it isn't. I just bought this calculator yesterday, and the book that came with it does not tell me how to program the Quadratic formula as well as other equations into this calculator. And someone I know in my class has the same one and told me that this can be...

Unable to Print the mails from Outlook express but do not give any error too. [ 0 Answers ]

Hello every one,I import all of my mails from Microsot Outlook to Outlook express.There is no problem in sending and receiving the mails.But the problem is that I can give the command to print the mails from outlook express.But no print will come and no error too.When opened the printer,there is no...

How to do e-0.05 on a calculator [ 5 Answers ]

Hi there, What are the exact steps I press on a calculator to do the following: - 40e-0.05 I keep getting the wrong answer? Any help is appreciated


View more questions Search