Jumat, 26 November 2010

Kalkulator VB.NET





















Public Class form1
    Dim temp1, temp2 As Double
    Dim Xoperator As String
    Private inputStatus As Boolean

' Input Angka 0 - 9
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click, Button3.Click, Button4.Click, Button5.Click, Button6.Click, Button7.Click, Button8.Click, Button9.Click, Buttonx.Click, Buttonxx.Click, Buttonkoma.Click
  
 If inputStatus = False Then
            TextBox1.Text += sender.text
        Else
            TextBox1.Text = sender.text
            inputStatus = False
        End If
    End Sub


Private Sub hitung()
        temp2 = Val(TextBox1.Text)
        Select Case (Xoperator)
        Case "+"
                temp1 = temp1 + temp2
         Case "-"
                temp1 = temp1 - temp2
         Case "/"
                temp1 = temp1 / temp2
         Case "*"
                temp1 = temp1 * temp2
        End Select
        TextBox1.Text = CStr(temp1)
        inputStatus = True
End Sub


Private Sub tambah_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tambah.Click, bagi.Click, kurang.Click, kali.Click
        If TextBox1.Text.Length <> 0 Then
            If Xoperator = String.Empty Then
                temp1 = Val(TextBox1.Text)
                TextBox1.Text = String.Empty
            Else
                hitung()
            End If
            Xoperator = sender.text
        End If
    End Sub


Private Sub BtnHitung_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnHitung.Click
        If TextBox1.Text.Length <> 0 AndAlso temp1 <> 0 Then
            hitung()
            Xoperator = ""
        End If
End Sub


Private Sub BtnHapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnHapus.Click
        TextBox1.Text = ""
        temp1 = 0
        temp2 = 0
End Sub

Private Sub BtnBackSpace_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnBackSpace.Click
        Dim xx As Integer
        xx = TextBox1.Text.Length
        If xx > 0 Then
            TextBox1.Text = TextBox1.Text.Remove(xx - 1, 1)
        End If
End Sub

End Class




. Download Program .

 


Tidak ada komentar:

Posting Komentar