Welcome back to my blog arybyan

Kalkulator Model klasik VB6

Kalkulator Model klasik VB6


Desain awal Buatlah ketentuan seperti ini :


 Text1.Text 
Name = Text1

Command1
Name    = Cmd_0
Caption = 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_4
Caption = 4

Command7
Name    = Cmd_5
Caption = 5

Command8
Name    = Cmd_6
Caption = 6

Command9
Name    = Cmd_7
Caption = 7

Command10
Name    = Cmd_8
Caption = 8

Command11
Name    = Cmd_9
Caption = 9

Command12
Name    = Cmd_Bagi
Caption = /

Command13
Name    = Cmd_Kali
Caption = *

Command14
Name    = Cmd_Kurang
Caption = -

Command15
Name    = Cmd_Tambah
Caption = +

Command16
Name    = Cmd_Pangkat
Caption = ^

Command17
Name    = Cmd_sin
Caption = sin

Command18
Name    = Cmd_CE
Caption = CE

Command19
Name    = Cmd_Tan
Caption = tan

Command20
Name    = Cmd_Cos
Caption = cos

Command21Name    = Cmd_C
Caption = C

Command22
Name    = Cmd_Off
Caption = Off/Keluar


Listing Code

Dim Angka, Hasil As Double
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

Posting Komentar