Thursday, 5 December 2013

Program Kalkulator Visual Basic


Private pilihan As String
Private x As Double
Private y As Double

Private Sub bagi_Click()
pilihan = "bagi"
y = x
x = 0
Text2.Text = Text2.Text & text1.Text & " / "
text1.Text = ""
End Sub

Private Sub c_Click()
text1.Text = ""
Text2.Text = ""
End Sub

Private Sub ce_Click()
text1.Text = ""
End Sub

Private Sub cmdAngka_Click(Index As Integer)
text1.Text = text1.Text & cmdAngka(Index).Caption
x = text1.Text


End Sub



Private Sub hps_Click()
Dim txt As String
txt = text1.Text
If Len(txt) > 1 Then
text1.Text = Left$(txt, Len(txt) - 1)
Else
text1.Text = ""
End If
End Sub

Private Sub kali_Click()
pilihan = "kali"
y = x
x = 0
Text2.Text = Text2.Text & text1.Text & " * "
text1.Text = ""
End Sub

Private Sub koma_Click()
If text1.Text = "" Then
text1.Text = "0,"
Else
text1.Text = text1.Text & ","
End If
End Sub

Private Sub kurang_Click()
pilihan = "kurang"
y = x
x = 0
Text2.Text = Text2.Text & text1.Text & " - "
text1.Text = ""
End Sub

Private Sub mines_Click()
If x < 0 Then
text1.Text = -x
x = -x
Else
text1.Text = "-" & text1.Text
x = -x
End If
End Sub

Private Sub samadengan_Click()
Text2.Text = Text2.Text & text1.Text & " = "
If pilihan = "tambah" Then
x = y + x
text1.Text = x
ElseIf pilihan = "kurang" Then
x = y - x
text1.Text = x
ElseIf pilihan = "kali" Then
x = y * x
text1.Text = x
ElseIf pilihan = "bagi" And x <> 0 Then
x = y / x
text1.Text = x
Else
text1.Text = "Tidak Terdefinisi"
End If
End Sub

Private Sub tambah_Click()
pilihan = "tambah"
y = x
x = 0
Text2.Text = Text2.Text & text1.Text & " + "
text1.Text = ""
End Sub
 

No comments:

Post a Comment