Minggu, 10 Juni 2012

Membuat Calculator sederhana di Visual Basic

Siapkan 1 Form, dan 17 command botton


Dim kal, operator As String
Dim tanda As Boolean
Dim bil As Double

Private Sub cmdangka_Click(Index As Integer)
    If txtbil.Text = "0" And Index = 0 Then Exit Sub
    kal = kal + Trim(Str(Index))
    txtbil.Text = kal
End Sub

Private Sub cmdclear_Click()
 tanda = False
    kal = ""
    operator = ""
    txtbil.Text = "0"
End Sub

Private Sub cmdoperator_Click(Index As Integer)
Select Case Index
Case 0
bil2 = Val(kal)
If operator = "+" Then bil = bil + bil2
If operator = "-" Then bil = bil - bil2
If operator = "*" Then bil = bil * bil2
If operator = "/" Then bil = bil / bil2
txtbil.Text = bil
kal = Trim(Str(bil))
titik = False
Case 1
bil = Val(kal)
operator = "+"
kal = ""
titik = False
Case 2
    bil = Val(kal)
    operator = "-"
    kal = ""
    titik = False
Case 3
    bil = Val(kal)
    operator = "*"
    kal = ""
    titik = False
Case 4
    bil = Val(kal)
    operator = "/"
    kal = ""
    titik = False
Case 5
    If tanda = False And txtbil.Text = "0" Then kal = "0."
    If tanda = False And txtbil.Text <> "0" Then kal = kal & "."
    If tanda = True Then Exit Sub
    tanda = True
End Select
End Sub

Private Sub Form_Load()
    tanda = False
    kal = ""
    operator = ""
    txtbil.Text = "0"
    End Sub

Selengkapnya Download disini

Tidak ada komentar:

Posting Komentar

Silahkan berikan komentar anda di Postingan ini tanpa mengundang SARA dan Pornografi ^.^