VERSION 5.00
Begin VB.Form frmCalculator 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Calculator"
   ClientHeight    =   8340
   ClientLeft      =   7935
   ClientTop       =   3270
   ClientWidth     =   7890
   ForeColor       =   &H00000000&
   Icon            =   "frmCalculator.frx":0000
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   ScaleHeight     =   8340
   ScaleWidth      =   7890
   Begin VB.Timer Timer1 
      Interval        =   1000
      Left            =   480
      Top             =   7800
   End
   Begin VB.CommandButton cmdCalc 
      Caption         =   "Enter"
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Index           =   23
      Left            =   4620
      TabIndex        =   25
      Top             =   7560
      Width           =   2955
   End
   Begin VB.TextBox txt_Paper 
      Alignment       =   1  'Right Justify
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   3855
      Left            =   4620
      MultiLine       =   -1  'True
      ScrollBars      =   2  'Vertical
      TabIndex        =   24
      Top             =   240
      Width           =   2955
   End
   Begin VB.CommandButton cmdCalc 
      Caption         =   "="
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Index           =   22
      Left            =   7020
      TabIndex        =   23
      Top             =   7020
      Width           =   570
   End
   Begin VB.CommandButton cmdCalc 
      Caption         =   "+"
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Index           =   21
      Left            =   6420
      TabIndex        =   22
      Top             =   7020
      Width           =   570
   End
   Begin VB.CommandButton cmdCalc 
      Caption         =   "."
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Index           =   20
      Left            =   5820
      TabIndex        =   21
      Top             =   7020
      Width           =   570
   End
   Begin VB.CommandButton cmdCalc 
      Caption         =   "+/-"
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Index           =   19
      Left            =   5220
      TabIndex        =   20
      Top             =   7020
      Width           =   570
   End
   Begin VB.CommandButton cmdCalc 
      Caption         =   "0"
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Index           =   18
      Left            =   4620
      TabIndex        =   19
      Top             =   7020
      Width           =   555
   End
   Begin VB.CommandButton cmdCalc 
      Caption         =   "1/x"
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Index           =   17
      Left            =   7020
      TabIndex        =   18
      Top             =   6480
      Width           =   570
   End
   Begin VB.CommandButton cmdCalc 
      Caption         =   "-"
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Index           =   16
      Left            =   6420
      TabIndex        =   17
      Top             =   6480
      Width           =   570
   End
   Begin VB.CommandButton cmdCalc 
      Caption         =   "3"
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Index           =   15
      Left            =   5820
      TabIndex        =   16
      Top             =   6480
      Width           =   570
   End
   Begin VB.CommandButton cmdCalc 
      Caption         =   "2"
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Index           =   14
      Left            =   5220
      TabIndex        =   15
      Top             =   6480
      Width           =   570
   End
   Begin VB.CommandButton cmdCalc 
      Caption         =   "1"
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Index           =   13
      Left            =   4620
      TabIndex        =   14
      Top             =   6480
      Width           =   555
   End
   Begin VB.CommandButton cmdCalc 
      Caption         =   "%"
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Index           =   12
      Left            =   7020
      TabIndex        =   13
      Top             =   5940
      Width           =   570
   End
   Begin VB.CommandButton cmdCalc 
      Caption         =   "X"
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Index           =   11
      Left            =   6420
      TabIndex        =   12
      Top             =   5940
      Width           =   570
   End
   Begin VB.CommandButton cmdCalc 
      Caption         =   "6"
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Index           =   10
      Left            =   5820
      TabIndex        =   11
      Top             =   5940
      Width           =   570
   End
   Begin VB.CommandButton cmdCalc 
      Caption         =   "5"
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Index           =   9
      Left            =   5220
      TabIndex        =   10
      Top             =   5940
      Width           =   570
   End
   Begin VB.CommandButton cmdCalc 
      Caption         =   "4"
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Index           =   8
      Left            =   4620
      TabIndex        =   9
      Top             =   5940
      Width           =   555
   End
   Begin VB.CommandButton cmdCalc 
      Caption         =   "sqrt"
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Index           =   7
      Left            =   7020
      TabIndex        =   8
      Top             =   5400
      Width           =   570
   End
   Begin VB.CommandButton cmdCalc 
      Caption         =   "/"
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Index           =   6
      Left            =   6420
      TabIndex        =   7
      Top             =   5400
      Width           =   570
   End
   Begin VB.CommandButton cmdCalc 
      Caption         =   "9"
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Index           =   5
      Left            =   5820
      TabIndex        =   6
      Top             =   5400
      Width           =   570
   End
   Begin VB.CommandButton cmdCalc 
      Caption         =   "8"
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Index           =   4
      Left            =   5220
      TabIndex        =   5
      Top             =   5400
      Width           =   570
   End
   Begin VB.CommandButton cmdCalc 
      Caption         =   "7"
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Index           =   3
      Left            =   4620
      TabIndex        =   4
      Top             =   5400
      Width           =   555
   End
   Begin VB.CommandButton cmdCalc 
      Caption         =   "C"
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Index           =   2
      Left            =   6720
      TabIndex        =   3
      Top             =   4800
      Width           =   855
   End
   Begin VB.CommandButton cmdCalc 
      Caption         =   "CE"
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Index           =   1
      Left            =   5820
      TabIndex        =   2
      Top             =   4800
      Width           =   795
   End
   Begin VB.CommandButton cmdCalc 
      Caption         =   "Backspace"
      BeginProperty Font 
         Name            =   "Tw Cen MT Condensed"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Index           =   0
      Left            =   4620
      TabIndex        =   1
      Top             =   4800
      Width           =   1155
   End
   Begin VB.Label lblDisplay 
      Alignment       =   1  'Right Justify
      BackColor       =   &H00404000&
      BorderStyle     =   1  'Fixed Single
      Caption         =   "0."
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   20.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00FFFFFF&
      Height          =   615
      Left            =   4620
      TabIndex        =   0
      Top             =   4080
      Width           =   2955
   End
End
Attribute VB_Name = "frmCalculator"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private mdblResult           As Double
Private mdblSavedNumber      As Double
Private mstrDot              As String
Private mstrOp               As String
Private mstrDisplay          As String
Private mblnDecEntered       As Boolean
Private mblnOpPending        As Boolean
Private mblnNewEquals        As Boolean
Private mblnEqualsPressed    As Boolean
Private mintCurrKeyIndex    As Integer

Private Sub cmdCalc_KeyPress(Index As Integer, KeyAscii As Integer)
    
    Dim intIndex    As Integer
    
    If KeyAscii = vbKeyReturn Then
        intIndex = 23
        cmdCalc(intIndex).SetFocus
        cmdCalc_Click intIndex
    End If
End Sub

Private Sub Form_Load()

    Top = (Screen.Height - Height) / 2
    Left = (Screen.Width - Width) / 2

End Sub


Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

    Dim intIndex    As Integer
    
    Select Case KeyCode
        Case vbKeyBack:             intIndex = 0
        Case vbKeyDelete:           intIndex = 1
        Case vbKeyEscape:           intIndex = 2
        Case vbKey0, vbKeyNumpad0:  intIndex = 18
        Case vbKey1, vbKeyNumpad1:  intIndex = 13
        Case vbKey2, vbKeyNumpad2:  intIndex = 14
        Case vbKey3, vbKeyNumpad3:  intIndex = 15
        Case vbKey4, vbKeyNumpad4:  intIndex = 8
        Case vbKey5, vbKeyNumpad5:  intIndex = 9
        Case vbKey6, vbKeyNumpad6:  intIndex = 10
        Case vbKey7, vbKeyNumpad7:  intIndex = 3
        Case vbKey8, vbKeyNumpad8:  intIndex = 4
        Case vbKey9, vbKeyNumpad9:  intIndex = 5
        Case vbKeyDecimal:          intIndex = 20
        Case vbKeyAdd:              intIndex = 21
        Case vbKeySubtract:         intIndex = 16
        Case vbKeyMultiply:         intIndex = 11
        Case vbKeyDivide:           intIndex = 6
        Case vbKeyReturn:           intIndex = 23
        Case Else:                  Exit Sub
    End Select
    
    cmdCalc(intIndex).SetFocus
    cmdCalc_Click intIndex
    
End Sub


Private Sub Form_KeyPress(KeyAscii As Integer)
    
    Dim intIndex    As Integer
    
    Select Case Chr$(KeyAscii)
        Case "S", "s":  intIndex = 7
        Case "P", "p":  intIndex = 12
        Case "R", "r":  intIndex = 17
        Case "X", "x":  intIndex = 11
        Case "=":       intIndex = 22
        Case Else:      Exit Sub
    End Select
    If KeyAscii = vbKeyReturn Then intIndex = 23
    cmdCalc(intIndex).SetFocus
    cmdCalc_Click intIndex

End Sub

Private Sub cmdCalc_Click(Index As Integer)

    Dim strPressedKey   As String
    
    mintCurrKeyIndex = Index
    
    If mstrDisplay = "ERROR" Then
        mstrDisplay = ""
    End If
    
    strPressedKey = cmdCalc(Index).Caption
    
    Select Case strPressedKey
        Case "0", "1", "2", "3", "4", _
             "5", "6", "7", "8", "9"
            If mblnOpPending Then
                mstrDisplay = ""
                mblnOpPending = False
            End If
            If mblnEqualsPressed Then
                mstrDisplay = ""
                mblnEqualsPressed = False
            End If
            mstrDisplay = mstrDisplay & strPressedKey
        Case "."
            If mblnOpPending Then
                mstrDisplay = ""
                mblnOpPending = False
            End If
            If mblnEqualsPressed Then
                mstrDisplay = ""
                mblnEqualsPressed = False
            End If
            If InStr(mstrDisplay, ".") > 0 Then
                Beep
            Else
                mstrDisplay = mstrDisplay & strPressedKey
            End If
        Case "+", "-", "X", "/"
            Dim strPrefix As String
            Dim TempStr As String
            
            TempStr = Format(mstrDisplay, "#,###.00")
            Select Case strPressedKey
            Case "+"
                strPrefix = "+"
                mstrDisplay = mdblResult + Val(mstrDisplay)
            Case "-"
                strPrefix = "-"
                mstrDisplay = mdblResult - Val(mstrDisplay)
            Case "X"
                strPrefix = "x"
                mstrDisplay = mdblResult * Val(mstrDisplay)
            Case "/"
                strPrefix = "/"
                mstrDisplay = mdblResult / Val(mstrDisplay)
            End Select
            If txt_Paper = "" Then
                txt_Paper.Text = txt_Paper.Text & TempStr & vbCrLf
            Else
                txt_Paper.Text = txt_Paper.Text & strPrefix & TempStr & vbCrLf
            End If
            
            mdblResult = Val(mstrDisplay)
            mstrOp = strPressedKey
            mblnOpPending = True
            mblnDecEntered = False
            mblnNewEquals = True
            
        Case "%"
            mdblSavedNumber = (Val(mstrDisplay) / 100) * mdblResult
            mstrDisplay = Format$(mdblSavedNumber)
        Case "=", "Enter"
            If mblnNewEquals Then
                mdblSavedNumber = Val(mstrDisplay)
                mblnNewEquals = False
            End If
            Select Case mstrOp
                Case "+"
                    mdblResult = mdblResult + mdblSavedNumber
                Case "-"
                    mdblResult = mdblResult - mdblSavedNumber
                Case "X"
                    mdblResult = mdblResult * mdblSavedNumber
                Case "/"
                    If mdblSavedNumber = 0 Then
                        mstrDisplay = "ERROR"
                    Else
                        mdblResult = mdblResult / mdblSavedNumber
                    End If
                Case Else
                    mdblResult = Val(mstrDisplay)
            End Select
            If mstrDisplay <> "ERROR" Then
                mstrDisplay = Format$(mdblResult)
            End If
            mblnEqualsPressed = True
        Case "+/-"
            If mstrDisplay <> "" Then
                If Left$(mstrDisplay, 1) = "-" Then
                    mstrDisplay = Right$(mstrDisplay, 2)
                Else
                    mstrDisplay = "-" & mstrDisplay
                End If
            End If
        Case "Backspace"
            If Val(mstrDisplay) <> 0 Then
                mstrDisplay = Left$(mstrDisplay, Len(mstrDisplay) - 1)
                mdblResult = Val(mstrDisplay)
            End If
        Case "CE"
            txt_Paper.Text = ""
            mstrDisplay = ""
        Case "C"
            txt_Paper.Text = ""
            mstrDisplay = ""
            mdblResult = 0
            mdblSavedNumber = 0
        Case "1/x"
            If Val(mstrDisplay) = 0 Then
                mstrDisplay = "ERROR"
            Else
                mdblResult = Val(mstrDisplay)
                mdblResult = 1 / mdblResult
                mstrDisplay = Format$(mdblResult)
            End If
        Case "sqrt"
            If Val(mstrDisplay) < 0 Then
                mstrDisplay = "ERROR"
            Else
                mdblResult = Val(mstrDisplay)
                mdblResult = Sqr(mdblResult)
                mstrDisplay = Format$(mdblResult)
            End If
        'Case "Enter"
        
    End Select
        
    If mstrDisplay = "" Then
        lblDisplay = "0."
    Else
        mstrDot = IIf(InStr(mstrDisplay, ".") > 0, "", ".")
        lblDisplay = mstrDisplay & mstrDot
        If Left$(lblDisplay, 1) = "0" Then
            lblDisplay = Mid$(lblDisplay, 2)
        End If
    End If
    
    If lblDisplay = "." Then lblDisplay = "0."
    
End Sub

Private Sub Timer1_Timer()
  On Error Resume Next
  Debug.Print "/ " & Screen.ActiveForm.Name & " / " & Screen.ActiveControl.Name & " /"
End Sub

Private Sub txt_Paper_KeyPress(KeyAscii As Integer)
    
    Dim intIndex    As Integer
    
    If KeyAscii = vbKeyReturn Then
        intIndex = 23
        cmdCalc(intIndex).SetFocus
        cmdCalc_Click intIndex
    End If
End Sub
