Kalkulator Model klasik VB6
Desain awal Buatlah ketentuan seperti ini :
Text1.Text
Name = Text1
Command1
Name = Cmd_0Caption = 0
Command2
Name = Cmd_Sama_Dengan
Caption = =
Command3
Name = Cmd_1
Caption = 1
Command4
Name = Cmd_2
Caption = 2
Command5
Name = Cmd_3
Caption = 3
Command6
Name = Cmd_4Caption = 4
Command7
Name = Cmd_5Caption = 5
Command8
Name = Cmd_6Caption = 6
Command9
Name = Cmd_7Caption = 7
Command10
Name = Cmd_8Caption = 8
Command11
Name = Cmd_9Caption = 9
Command12
Name = Cmd_BagiCaption = /
Command13
Name = Cmd_KaliCaption = *
Command14
Name = Cmd_KurangCaption = -
Command15
Name = Cmd_TambahCaption = +
Command16
Name = Cmd_PangkatCaption = ^
Name = Cmd_sin
Caption = sin
Command18
Name = Cmd_CECaption = CE
Command19
Name = Cmd_TanCaption = tan
Command20
Name = Cmd_CosCaption = cos
Command21Name = Cmd_C
Caption = C
Command22
Name = Cmd_OffCaption = Off/Keluar
Listing Code
Dim Operator As String
Private Sub cmd_0_Click()
If Text1.Text = "0" Then
Text1.Text = "0"
Else
Text1.Text = Text1.Text & "0"
End If
End Sub
Private Sub cmd_1_Click()
If Text1.Text = "0" Then
Text1.Text = "1"
Else
Text1.Text = Text1.Text & "1"
End If
End Sub
Private Sub cmd_2_Click()
If Text1.Text = "0" Then
Text1.Text = "2"
Else
Text1.Text = Text1.Text & "2"
End If
End Sub
Private Sub cmd_3_Click()
If Text1.Text = "0" Then
Text1.Text = "3"
Else
Text1.Text = Text1.Text & "3"
End If
End Sub
Private Sub cmd_4_Click()
If Text1.Text = "0" Then
Text1.Text = "4"
Else
Text1.Text = Text1.Text & "4"
End If
End Sub
Private Sub cmd_5_Click()
If Text1.Text = "0" Then
Text1.Text = "5"
Else
Text1.Text = Text1.Text & "5"
End If
End Sub
Private Sub cmd_6_Click()
If Text1.Text = "0" Then
Text1.Text = "6"
Else
Text1.Text = Text1.Text & "6"
End If
End Sub
Private Sub cmd_7_Click()
If Text1.Text = "0" Then
Text1.Text = "7"
Else
Text1.Text = Text1.Text & "7"
End If
End Sub
Private Sub cmd_8_Click()
If Text1.Text = "0" Then
Text1.Text = "8"
Else
Text1.Text = Text1.Text & "8"
End If
End Sub
Private Sub cmd_9_Click()
If Text1.Text = "0" Then
Text1.Text = "9"
Else
Text1.Text = Text1.Text & "9"
End If
End Sub
Private Sub cmd_bagi_Click()
If Angka = 0 Then
Angka = Val(Text1.Text)
Else
Angka = Angka / Val(Text1.Text)
End If
Operator = "/"
Text1.Text = 0
End Sub
Private Sub cmd_c_Click()
Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
End Sub
Private Sub cmd_ce_Click()
Text1.Text = "0"
Angka = 0
Hasil = 0
Operator = ""
End Sub
Private Sub cmd_kali_Click()
If Angka = 0 Then
Angka = Val(Text1.Text)
Else
Angka = Angka * Val(Text1.Text)
End If
Operator = "*"
Text1.Text = 0
End Sub
Private Sub cmd_kurang_Click()
If Angka = 0 Then
Angka = Val(Text1.Text)
Else
Angka = Angka - Val(Text1.Text)
End If
Operator = "-"
Text1.Text = 0
End Sub
Private Sub cmd_off_Click()
End
End Sub
Private Sub cmd_pangkat_Click()
If Angka = 0 Then
Angka = Val(Text1.Text)
Else
Angka = Angka ^ Val(Text1.Text)
End If
Operator = "^"
Text1.Text = 0
End Sub
Private Sub cmd_samadengan_Click()
If Operator = "+" Then
Hasil = Angka + Val(Text1.Text)
Text1.Text = Hasil
ElseIf Operator = "-" Then
Hasil = Angka - Val(Text1.Text)
Text1.Text = Hasil
ElseIf Operator = "*" Then
Hasil = Angka * Val(Text1.Text)
Text1.Text = Hasil
ElseIf Operator = "/" Then
Hasil = Angka / Val(Text1.Text)
Text1.Text = Hasil
ElseIf Operator = "^" Then
Hasil = Angka ^ Val(Text1.Text)
Text1.Text = Hasil
End If
End Sub
Private Sub cmd_tambah_Click()
If Angka = 0 Then
Angka = Val(Text1.Text)
Else
Angka = Angka + Val(Text1.Text)
End If
Operator = "+"
Text1.Text = 0
End Sub