Calculator Program


The Interface                                                                                     Click to  Run Calculator Program

The Program

 
 
Option Explicit
Dim ready As Integer
Dim key As Integer
Dim readout_Value As Variant
Dim a, b, c, d, e, f, g As Variant
Dim memo As Variant



Private Sub Form_Load()

Left = (Screen.Width - Width) \ 2
Top = (Screen.Height - Height) \ 2

End Sub



Sub assess_readout()
readout_Value = Val(display.Caption)
End Sub

Private Sub ButtonNum_Click(Index As Integer)

If ready > 0 Then
If ready < 30 Then
display.Caption = display.Caption + Right$(Str$(Index), 1)

ready = ready + 1
End If

Else
display.Caption = Right$(Str$(Index), 1)
ready = 1
End If

assess_readout
End Sub

Private Sub Button_Zero_Click()
If ready > 0 Then
display.Caption = display.Caption + "0"
Else
display.Caption = "0"
ready = ready + 1
End If
assess_readout
End Sub


Private Sub Clear_Click()

display.Caption = "0"
readout_Value = "0"
ready = 0

End Sub


Private Sub ClearAll_Click()

display.Caption = "0"
readout_Value = "0"
memo = 0

End Sub


Private Sub Equal_Click()


assess_readout
If key = 1 Then
e = readout_Value + a
ElseIf key = 2 Then
e = b - readout_Value

ElseIf key = 3 Then
e = readout_Value * c

ElseIf key = 5 Then
e = (f * readout_Value) / 100

ElseIf key = 4 And readout_Value <> 0 Then
e = d / readout_Value

Else

GoTo error

End If

display.Caption = Str(e)
GoTo finish

error: display.Caption = "E"

finish:

ready = 0


End Sub


Private Sub MemoCancel_Click()
memo = 0
End Sub


Private Sub Memo_Cancel_Click()

End Sub

Private Sub Memory_Click()
assess_readout
memo = readout_Value
ready = 0
End Sub

Private Sub Operator_Click(Index As Integer)


assess_readout
If Index = 11 Then
a = readout_Value
key = 1

ElseIf Index = 12 Then
b = readout_Value
key = 2

ElseIf Index = 13 Then
c = readout_Value
key = 3

ElseIf Index = 14 Then
d = readout_Value
key = 4

ElseIf Index = 15 Then
f = readout_Value
key = 5

End If
ready = 0


End Sub


Private Sub Percent_Click()
assess_readout
readout_Value = readout_Value / 100
display.Caption = Str$(readout_Value)
ready = 0


End Sub


Private Sub Plus_minus_Click()
assess_readout
g = -1 * readout_Value
readout_Value = g
display.Caption = Str$(readout_Value)
assess_readout


End Sub


Private Sub Poin_Click()
Static point_lock As Integer
If point_lock = 0 And ready < 20 Then
display.Caption = display.Caption + "."
ready = ready + 1
End If
assess_readout

End Sub

Private Sub Recall_Click()
display.Caption = Str$(memo)

End Sub

Private Sub SqRoot_Click()
assess_readout
If readout_Value >= 0 Then
display.Caption = Str$(Sqr(readout_Value))
Else
display.Caption = "E"
End If

ready = 0

End Sub

Private Sub Summation_Click()
assess_readout

memo = memo + readout_Value

ready = 0

End Sub