follow me =)

Selasa, 3 April 2012

simple calculator using vb

my calculator
Hari ini aku hendak kongsikan simple calculator menggunakan vb... Dalam internet memang melambak coding untuk calculator ini... Tapi apa pun, aku nak kongsikan juga... Mungkin dapat membantu serba sedikit yang memerlukan bantuan...

Public Class Form1
    Dim num1, num2 As Double
    Dim opr As String

    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        '0
        TextBox1.Text = TextBox1.Text & "0"
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        '1
        TextBox1.Text = TextBox1.Text & "1"
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        '2
        TextBox1.Text = TextBox1.Text & "2"
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        '3
        TextBox1.Text = TextBox1.Text & "3"
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        '4
        TextBox1.Text = TextBox1.Text & "4"
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        '5
        TextBox1.Text = TextBox1.Text & "5"
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        '6
        TextBox1.Text = TextBox1.Text & "6"
    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        '7
        TextBox1.Text = TextBox1.Text & "7"
    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        '8
        TextBox1.Text = TextBox1.Text & "8"
    End Sub

    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        '9
        TextBox1.Text = TextBox1.Text & "9"
    End Sub

    Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
        'C
        TextBox1.Text = ""
    End Sub

    Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
        '+
        num1 = Val(TextBox1.Text)
        opr = "+"
        TextBox1.Text = ""
    End Sub

    Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
        '-
        num1 = Val(TextBox1.Text)
        opr = "-"
        TextBox1.Text = ""
    End Sub

    Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
        'x
        num1 = Val(TextBox1.Text)
        opr = "*"
        TextBox1.Text = ""
    End Sub

    Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click
        '/
        num1 = Val(TextBox1.Text)
        opr = "/"
        TextBox1.Text = ""
    End Sub

    Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
        '=
        num2 = Val(TextBox1.Text)
        Select Case opr
            Case "+" : TextBox1.Text = num1 + num2
            Case "-" : TextBox1.Text = num1 - num2
            Case "*" : TextBox1.Text = num1 * num2
            Case "/" : TextBox1.Text = num1 / num2
        End Select
    End Sub
End Class

p/s : good luck!!... sekarang tengah buat mini project... simple je buat, tajuk nya bus online ticket... =)

3 ulasan:

  1. saya pon ade belajar buat ni..utk assignment individu..

    BalasPadam
  2. saya pon ade belajar basic programming ni.and buat application calculator ni jugak.. :D

    BalasPadam
  3. rsnye mmg dia ajar yg sama je utk basic programming ni kan...

    BalasPadam