memory and memory recall buttons for a calculator

I'm very new to programming and to visual basic 6.  I have made a calculator program and the code is as follows:

Option Explicit

Dim bDecimal As Boolean     ' Declares variable to create a flag for the decimal
Dim Op1, Op2                ' Previously input operand.
Dim NumOps As Integer       ' Number of operands.
Dim LastInput               ' Indicate type of last keypress event.
Dim OpFlag                  ' Indicate pending operation.
Dim TempOutput              ' Temporary storage

' Click event procedure for number keys (0-9).
' Append new number to the number in the display.

Private Sub cmdNumber_Click(index As Integer)
    If LastInput <> "NUMS" Then
        txtOutput.Text = Format(0, ".")
        bDecimal = False
    End If
    If bDecimal Then
        txtOutput.Text = txtOutput.Text + cmdNumber(index).Caption
    Else
        txtOutput.Text = Left(txtOutput.Text, InStr(txtOutput.Text, Format(0, ".")) - 1) + cmdNumber(index).Caption + Format(0, ".")
    End If
    If LastInput = "NEG" Then txtOutput.Text = "-" & txtOutput.Text
    LastInput = "NUMS"
End Sub

' If the immediately preceeding keypress was part of a
' number, increments NumOps. If one operand is present,
' set Op1. If two are present, set Op1 equal to the
' result of the operation on Op1 and the current
' input string, and display the result.

Private Sub cmdOperator_Click(index As Integer)
    TempOutput = txtOutput.Text
    If LastInput = "NUMS" Then
        NumOps = NumOps + 1
    End If
    Select Case NumOps
        Case 0
        If cmdOperator(index).Caption = "-" And LastInput <> "NEG" Then
            txtOutput.Text = "-" & txtOutput.Text
            LastInput = "NEG"
        End If
        Case 1
        Op1 = txtOutput.Text
        If cmdOperator(index).Caption = "-" And LastInput <> "NUMS" And OpFlag <> "=" Then
            txtOutput.Text = "-"
            LastInput = "NEG"
        End If
        Case 2
        Op2 = TempOutput
        Select Case OpFlag
            Case "+"
                Op1 = CDbl(Op1) + CDbl(Op2)
            Case "-"
                Op1 = CDbl(Op1) - CDbl(Op2)
            Case "*"
                Op1 = CDbl(Op1) * CDbl(Op2)
            Case "/"
                If Op2 = 0 Then
                   MsgBox "Can't divide by zero", 48, "Calculator"
                Else
                   Op1 = CDbl(Op1) / CDbl(Op2)
                End If
            Case "="
                Op1 = CDbl(Op2)
            Case "%"
                Op1 = CDbl(Op1) * CDbl(Op2)
            End Select
        txtOutput.Text = Op1
        NumOps = 1
    End Select
    If LastInput <> "NEG" Then
        LastInput = "OPS"
        OpFlag = cmdOperator(index).Caption
    End If
End Sub

' Reset the display and initializes variables.

Private Sub cmdCancel_Click()
    txtOutput = Format(0, "0")
    Op1 = 0
    Op2 = 0
    Form_Load
End Sub

' Cancel last entry made

Private Sub cmdCancelEntry_Click()
    txtOutput.Text = Format(0, "0")
    bDecimal = False
    LastInput = "CE"
End Sub

' Will check to see if there is already a decimal
' if there is then the decimal is disabled

Private Sub cmdDecimal_Click()
If LastInput = "NEG" Then
        txtOutput.Text = Format(0, "-0.")
    ElseIf LastInput <> "NUMS" Then
        txtOutput.Text = Format(0, "0.")
    End If
    bDecimal = True
    LastInput = "NUMS"
End Sub

' Unload form

Private Sub cmdExit_Click()
End
End Sub

' Calculates the percent of txtOutput

Private Sub cmdPercent_Click()
    txtOutput.Text = txtOutput.Text / 100
    LastInput = "Ops"
    OpFlag = "%"
    NumOps = NumOps + 1
    bDecimal = True
End Sub

' Initialization routine for the form.
' Set all variables to initial values
' sets the flag to off when the form loads

Private Sub Form_Load()
bDecimal = False
NumOps = 0
LastInput = "NONE"
OpFlag = " "
txtOutput = Format(0, "0")
cmdDecimal.Caption = Format(0, ".")
End Sub

i need to have a memory button and a memory recall button.  Can someone please help me with the code for this.  Thanks in advance.


forbiddenRAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

crazymanCommented:
you could use the save setting and getsetting command.


in the save button use
savesetting app.exename,"settings","memory",YourValue


then in the recall button

YourValue=getsetting(app.exename,"settings","memory")
0
forbiddenRAuthor Commented:
The simpler the better if at all possible.  I haven't been taught how to use the savesetting/getsetting command yet.  So I would like to use something that I understand and that would fit easily into my code.  Please and thank you.
0
crazymanCommented:
If you wanted the value to remain in memory just as long as the calculator was running you could simply use a static variable to hold the current memory data and recall it when ever needed.


Private Sub SetMemory_Click()
    Memory "12345"
   
End Sub
Public Function Memory(Optional vNewVal As Variant) As Variant
    '''if a value is passed then the memory is changed
        ''' and new value returned
    '''otherwise the value is just returned
    Static vCurrentVal As Variant
    If Not IsMissing(vNewVal) Then vCurrentVal = vNewVal
    Memory = vCurrentVal
End Function

Private Sub GetMemory_Click()
    MsgBox Memory
End Sub


0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
crazymanCommented:
You could of course just use a public variable which is probably the easiest way.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.