Kamis, 09 Mei 2013

Latihan 9 Visual Basic - Aplikasi Kalkulator

Latihan 9 Visual Basic  - Aplikasi Kalkulator


Dim angka(1 To 2) As Single

Dim operator As String

Private Sub cmdAngka_Click(Index As Integer)
    Text1.Text = Text1.Text & cmdAngka(Index).Caption
End Sub

Private Sub cmdHapus_Click()
    Text1.Text = ""
End Sub

Private Sub cmdOperator_Click(Index As Integer)
    If Text1.Text = "" Then Exit Sub
 
    angka(1) = CSng(Text1.Text)
    operator = cmdOperator(Index).Caption
    Text1.Text = ""
End Sub

Private Sub cmdHitung_Click()
    Dim hasil As Single
     
    If Text1.Text = "" Then Exit Sub
 
    angka(2) = CSng(Text1.Text)
 
    Select Case operator
    Case "+"
        hasil = angka(1) + angka(2)
    Case "-"
        hasil = angka(1) - angka(2)
    Case "*"
        hasil = angka(1) * angka(2)
    Case "/"
        hasil = angka(1) / angka(2)
    End Select
 
    Text1.Text = hasil
End Sub


0 komentar:

Posting Komentar

 
Design by Wordpress Theme Template Blog Free | Bloggerized by Free Blogger Templates | coupon codes