Simple calculator 1.0
Submitted By:
harirulez
Rating:





(
Rate It)
VERSION 5.00
Begin VB.Form Form1
BackColor = &H00000000&
Caption = "Simple Calculator"
ClientHeight = 5550
ClientLeft = 60
ClientTop = 345
ClientWidth = 8670
BeginProperty Font
Name = "Courier"
Size = 9.75
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
LinkTopic = "Form1"
ScaleHeight = 5550
ScaleWidth = 8670
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton Command4
BackColor = &H00808080&
Caption = "About"
Height = 495
Left = 240
Style = 1 'Graphical
TabIndex = 26
Top = 4680
Width = 2535
End
Begin VB.Frame Frame4
BackColor = &H00000000&
Caption = "Back Color"
ForeColor = &H00FFFFFF&
Height = 855
Left = 120
TabIndex = 24
Top = 480
Width = 2535
Begin VB.ListBox List1
Height = 450
ItemData = "Form1.frx":0000
Left = 120
List = "Form1.frx":0010
TabIndex = 25
Top = 240
Width = 2295
End
End
Begin VB.Frame Frame3
BackColor = &H00000000&
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 735
Left = 3240
TabIndex = 17
Top = 4440
Width = 5055
Begin VB.CommandButton Command3
BackColor = &H00808080&
Caption = "RESET"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 2640
Style = 1 'Graphical
TabIndex = 23
Top = 240
Width = 975
End
Begin VB.CommandButton Sign_btn
BackColor = &H00808080&
Caption = "+/-"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 1320
Style = 1 'Graphical
TabIndex = 22
Top = 240
Width = 855
End
Begin VB.CommandButton Command2
BackColor = &H00808080&
Caption = "ON/OFF"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 120
Style = 1 'Graphical
TabIndex = 21
Top = 240
Width = 855
End
Begin VB.CommandButton Exit_btn
BackColor = &H00808080&
Caption = "Exit"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 3960
Style = 1 'Graphical
TabIndex = 18
Top = 240
Width = 975
End
End
Begin VB.Frame Frame2
BackColor = &H00000000&
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 3135
Left = 7080
TabIndex = 12
Top = 1200
Width = 1215
Begin VB.CommandButton Divide
BackColor = &H00808080&
Caption = "\"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 240
MaskColor = &H00808080&
Style = 1 'Graphical
TabIndex = 16
Top = 2520
Width = 735
End
Begin VB.CommandButton Multiply
BackColor = &H00808080&
Caption = "X"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 240
MaskColor = &H00808080&
Style = 1 'Graphical
TabIndex = 15
Top = 1800
Width = 735
End
Begin VB.CommandButton Subtract
BackColor = &H00808080&
Caption = "_"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 240
MaskColor = &H00808080&
Style = 1 'Graphical
TabIndex = 14
Top = 1080
Width = 735
End
Begin VB.CommandButton Add
BackColor = &H00808080&
Caption = "+"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 240
MaskColor = &H00808080&
Style = 1 'Graphical
TabIndex = 13
Top = 360
Width = 735
End
End
Begin VB.Frame Frame1
BackColor = &H00000000&
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 3135
Left = 3240
TabIndex = 1
Top = 1200
Width = 3615
Begin VB.CommandButton Dot
BackColor = &H00808080&
Caption = "."
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 120
Style = 1 'Graphical
TabIndex = 20
Top = 2520
Width = 975
End
Begin VB.CommandButton Equal
BackColor = &H00808080&
Caption = "="
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 2520
Style = 1 'Graphical
TabIndex = 19
Top = 2520
Width = 975
End
Begin VB.CommandButton Command1
BackColor = &H00808080&
Caption = "9"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 9
Left = 2520
Style = 1 'Graphical
TabIndex = 11
Top = 1800
Width = 975
End
Begin VB.CommandButton Command1
BackColor = &H00808080&
Caption = "8"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 8
Left = 1320
Style = 1 'Graphical
TabIndex = 10
Top = 1800
Width = 975
End
Begin VB.CommandButton Command1
BackColor = &H00808080&
Caption = "7"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 7
Left = 120
Style = 1 'Graphical
TabIndex = 9
Top = 1800
Width = 975
End
Begin VB.CommandButton Command1
BackColor = &H00808080&
Caption = "6"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 6
Left = 2520
Style = 1 'Graphical
TabIndex = 8
Top = 1080
Width = 975
End
Begin VB.CommandButton Command1
BackColor = &H00808080&
Caption = "5"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 5
Left = 1320
Style = 1 'Graphical
TabIndex = 7
Top = 1080
Width = 975
End
Begin VB.CommandButton Command1
BackColor = &H00808080&
Caption = "4"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 4
Left = 120
Style = 1 'Graphical
TabIndex = 6
Top = 1080
Width = 975
End
Begin VB.CommandButton Command1
BackColor = &H00808080&
Caption = "3"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 3
Left = 2520
Style = 1 'Graphical
TabIndex = 5
Top = 360
Width = 975
End
Begin VB.CommandButton Command1
BackColor = &H00808080&
Caption = "2"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 2
Left = 1320
Style = 1 'Graphical
TabIndex = 4
Top = 360
Width = 975
End
Begin VB.CommandButton Command1
BackColor = &H00808080&
Caption = "1"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 1
Left = 120
Style = 1 'Graphical
TabIndex = 3
Top = 360
Width = 975
End
Begin VB.CommandButton Command1
BackColor = &H00808080&
Caption = "0"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 0
Left = 1320
Style = 1 'Graphical
TabIndex = 2
Top = 2520
Width = 975
End
End
Begin VB.TextBox Text1
Alignment = 1 'Right Justify
BeginProperty Font
Name = "Courier"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 3120
TabIndex = 0
Top = 480
Width = 5175
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim num1, num2, temp As String 'variables to store operands
Dim symbol As String 'to store sign of operation
Dim result As Double 'to store result of operation
Dim On_flag As Boolean 'flag to check status of calculator
Dim sign As Double 'to change the magnitude of a number
Dim clear_flag As Boolean
Private Sub about_Click(Index As Integer)
End Sub
'On clicking + button
Private Sub Add_Click()
If On_flag = True Then
symbol = "+"
num1 = Text1.Text
Text1.Text = ""
Else
MsgBox ("Switch ON the Calculator first!")
End If
End Sub
'On clicking - button
Private Sub Command1_Click(Index As Integer)
If On_flag = True Then
If clear_flag = True Then
Text1.Text = ""
clear_flag = False
End If
Text1.Text = Text1.Text + Command1(Index).Caption
Else
MsgBox ("Switch ON the Calculator first!")
End If
End Sub
'On Off Button
Private Sub Command2_Click()
If On_flag = False Then
On_flag = True
Else
On_flag = False
Text1.Text = ""
End If
End Sub
'Reset button
Private Sub Command3_Click()
clear_flag = False
Text1.Text = ""
sign = -1
End Sub
Private Sub Command4_Click()
frmAbout.Show
End Sub
'Divide button
Private Sub Divide_Click()
If On_flag = True Then
symbol = "\"
num1 = Text1.Text
Text1.Text = ""
Else
MsgBox ("Switch ON the Calculator first!")
End If
End Sub
Private Sub Dot_Click()
If InStr(Text1.Text, ".") Then
Exit Sub
End If
Dim str1 As String
str1 = "."
Text1.Text = Text1.Text + str1
End Sub
'Equal to button
Private Sub Equal_Click()
If On_flag = True Then
num2 = Text1.Text
'switch case to select operation
If Len(Text1.Text) > 0 Then
Select Case symbol
Case "+"
result = CDbl(num1) + CDbl(num2)
Text1.Text = result
Case "-"
result = CDbl(num1) - CDbl(num2)
Text1.Text = result
Case "X"
result = CDbl(num1) * CDbl(num2)
Text1.Text = result
Case "\"
If Not num2 = 0 Then
result = CDbl(num1) / CDbl(num2)
Text1.Text = result
Else
MsgBox ("Divide Error")
End If
End Select
clear_flag = True
Else
MsgBox ("Not enough Arguments!")
End If
Else
MsgBox ("Switch ON the Calculator first!")
End If
End Sub
Private Sub Exit_btn_Click()
Unload Me
End Sub
Private Sub Form_Load()
Text1.BackColor = &HFFC0C0
clear_flag = False
On_flag = False
sign = -1
End Sub
Private Sub List1_Click()
Dim i As Integer
i = List1.ListIndex
Select Case i
Case 0:
Text1.BackColor = &HFFC0C0
Case 1:
Text1.BackColor = &HC0FFC0
Case 2:
Text1.BackColor = &HC0FFFF
Case 3:
Text1.BackColor = &HFFC0FF
End Select
End Sub
Private Sub Multiply_Click()
If On_flag = True Then
symbol = "X"
num1 = Text1.Text
Text1.Text = ""
Else
MsgBox ("Switch ON the Calculator first!")
End If
End Sub
Private Sub Sign_btn_Click()
If On_flag = True Then
temp = CDbl(Text1.Text)
temp = sign * temp
Text1.Text = temp
Else
MsgBox ("Switch ON the Calculator first!")
End If
End Sub
Private Sub Subtract_Click()
If On_flag = True Then
symbol = "-"
num1 = Text1.Text
Text1.Text = ""
Else
MsgBox ("Switch ON the Calculator first!")
End If
End Sub