by RAJARATHNAM.L (3 Submissions)
Category: Math/Dates
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Mon 19th April 2004
Date Added: Mon 8th February 2021
Rating: (1 Votes)
The code performs the task of an calculator.In this simple application background color can be changed and options like refresh,exit,quick
Dim ans As Integer
Dim choice As Integer
Dim cho As Integer
Dim i As Integer
Dim a As Integer
Private Sub Command1_Click(Index As Integer)
Text1.Text = Text1.Text + "1"
End Sub
Private Sub Command10_Click()
If Val(Text1.Text) = 0 Then
Text1.Text = ""
Else
Text1.Text = Val(Text1.Text) \ 10
If Val(Text1.Text) = 0 Then
Text1.Text = ""
End If
End If
End Sub
Private Sub Command11_Click(Index As Integer)
Text1.Text = Text1.Text + "0"
End Sub
Private Sub Command12_Click()
Text1.Text = Text1.Text + "."
End Sub
Private Sub Command13_Click()
choice = 1
Text4.Text = ""
Text2.Text = Text2.Text + " +"
calculate
End Sub
Private Sub Command14_Click()
choice = 2
Text4.Text = ""
Text2.Text = Text2.Text + " -"
calculate
End Sub
Private Sub Command15_Click()
choice = 3
Text4.Text = ""
Text2.Text = Text2.Text + " *"
calculate
End Sub
Private Sub Command16_Click()
choice = 4
Text4.Text = ""
Text2.Text = Text2.Text + " /"
calculate
End Sub
Private Sub Command17_Click()
Select Case cho
Case 1
Text3.Text = Val(Text1.Text)
Text1.Text = ""
Text1.Text = Val(Text2.Text) + Val(Text3.Text)
Text4.Text = Text1.Text
Case 2
Text3.Text = Val(Text1.Text)
Text1.Text = ""
Text1.Text = Val(Text2.Text) - Val(Text3.Text)
Text4.Text = Text1.Text
Case 3
Text3.Text = Val(Text1.Text)
Text1.Text = ""
Text1.Text = Val(Text2.Text) * Val(Text3.Text)
Text4.Text = Text1.Text
Case 4
Text3.Text = Val(Text1.Text)
Text1.Text = ""
If Val(Text3.Text) = 0 Then
MsgBox "Zero Divide Error - Value Is Infinity"
Text3.Text = ""
Text4.Text = ""
Else
Text1.Text = Val(Text2.Text) / Val(Text3.Text)
Text4.Text = Text1.Text
End If
Case 5
Text4.Text = 1
Text3.Text = Text1.Text
For i = 1 To Val(Text1.Text) Step 1
Text4.Text = Val(Text4.Text) * Val(Text2.Text)
Next
Text1.Text = Text4.Text
End Select
End Sub
Private Sub Command18_Click()
Text1.Text = Text4.Text
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
End Sub
Private Sub Command19_Click()
Text2.Text = Text1.Text
End Sub
Private Sub Command2_Click(Index As Integer)
Text1.Text = Text1.Text + "2"
End Sub
Private Sub Command20_Click()
Text3.Text = Text1.Text
End Sub
Private Sub Command22_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text1.SetFocus
End Sub
Private Sub Command23_Click()
Text2.Text = Text1.Text
Text3.Text = "Cube"
Text1.Text = Val(Text1.Text) * Val(Text1.Text) * Val(Text1.Text)
Text4.Text = Text1.Text
End Sub
Private Sub Command24_Click()
Text3.Text = ""
Text4.Text = ""
Text2.Text = Text1.Text
Text1.Text = ""
Text1.SetFocus
cho = 5
End Sub
Private Sub Command25_Click()
Text2.Text = Text1.Text
Text3.Text = "Squared"
Text1.Text = Val(Text1.Text) * Val(Text1.Text)
Text4.Text = Text1.Text
End Sub
Private Sub Command26_Click()
For j = 1 To 200 Step 1
For i = 1 To 800 Step 1
Circle (Rnd * 15000, Rnd * 10000), Rnd * 100, RGB(Rnd * 255, 0, 0)
Next
Next
For j = 1 To 200 Step 1
For i = 1 To 500 Step 1
Circle (Rnd * 15000, Rnd * 10000), Rnd * 100, RGB(0, 0, 0)
Next
Next
MsgBox " Thankhyou "
End
End Sub
Private Sub Command27_Click()
Text1.Text = "0"
End Sub
Private Sub Command28_Click()
If a = 0 Then
For j = 1 To 200 Step 1
For i = 1 To 800 Step 1
Circle (Rnd * 15000, Rnd * 10000), Rnd * 100, RGB(Rnd * 255, 0, 0)
Next
Next
a = a + 1
Else
For j = 1 To 300 Step 1
For i = 1 To 900 Step 1
Circle (Rnd * 15000, Rnd * 10000), Rnd * 100, RGB(0, 0, 0)
Next
Next
a = a - 1
End If
Text1.Text = "Calculator - Chocky "
Command22.SetFocus
End Sub
Private Sub Command29_Click()
End
End Sub
Private Sub Command3_Click(Index As Integer)
Text1.Text = Text1.Text + "3"
End Sub
Private Sub Command4_Click(Index As Integer)
Text1.Text = Text1.Text + "4"
End Sub
Private Sub Command5_Click(Index As Integer)
Text1.Text = Text1.Text + "5"
End Sub
Private Sub Command6_Click(Index As Integer)
Text1.Text = Text1.Text + "6"
End Sub
Private Sub Command7_Click(Index As Integer)
Text1.Text = Text1.Text + "7"
End Sub
Private Sub Command8_Click(Index As Integer)
Text1.Text = Text1.Text + "8"
End Sub
Private Sub Command9_Click(Index As Integer)
Text1.Text = Text1.Text + "9"
End Sub
Private Sub calculate()
Select Case choice
Case 1
Text2.Text = Text1.Text
Text1.Text = ""
Text1.SetFocus
Text3.Text = Text1.Text
cho = 1
Case 2
Text2.Text = Text1.Text
Text1.Text = ""
Text1.SetFocus
Text3.Text = Text1.Text
cho = 2
Case 3
Text2.Text = Text1.Text
Text1.Text = ""
Text1.SetFocus
Text3.Text = Text1.Text
cho = 3
Case 4
Text2.Text = Text1.Text
Text1.Text = ""
Text1.SetFocus
Text3.Text = Text1.Text
cho = 4
End Select
End Sub
No comments have been posted about The code performs the task of an calculator.In this simple application background color can be chan. Why not be the first to post a comment about The code performs the task of an calculator.In this simple application background color can be chan.