Jumat, 27 Mei 2016

CONTOH PEMBUATAN KALKULATOR SEDERHANA PADA VB 10




Public Class Form1



    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim a, b, total As Integer

        a = TextBox1.Text

        b = TextBox2.Text



        total = a * b

        TextBox3.Text = total

    End Sub



    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

        Dim a, b, total As Integer

        a = TextBox1.Text

        b = TextBox2.Text



        total = a / b

        TextBox3.Text = total

    End Sub



  





 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        Dim a, b, total As Integer

        a = TextBox1.Text

        b = TextBox2.Text



        total = a + b

        TextBox3.Text = total

    End Sub



    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click

        Dim a, b, total As Integer

        a = TextBox1.Text

        b = TextBox2.Text



        total = a - b

        TextBox3.Text = total

    End Sub



    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        Dim a, b, total As Integer

        a = TextBox1.Text

        b = TextBox2.Text



        total = a Mod b

        TextBox3.Text = total

    End Sub



    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click

        Dim a, b, total As Integer

        a = TextBox1.Text

        b = TextBox2.Text



        TextBox3.ForeColor = Color.Plum

        TextBox3.Text = total

    End Sub





    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load



    End Sub

End Class





Penjelasan

Dim a, b, total As Integer : Digunakan untuk mendeklarasikan variable a, b dan  total

a = TextBox1.Text          : a di deklarasikan sebagai textbox1



b = TextBox2.Text          : b di deklarasikan sebagai textbox2



total = a Mod b            : Total dideklarasikan untuk memproses mod pada variable a                                                dan variable b



total = a x b              : Total dideklarasikan untuk memproses perkalian pada

  variable a  dan variable b



total = a / b              : Total dideklarasikan untuk memproses pembagian pada

  variable a  dan variable b



total = a + b              : Total dideklarasikan untuk memproses penjumlahan pada

  variable a  dan variable b



total = a - b              : Total dideklarasikan untuk memproses pengurangan pada

  variable a  dan variable b



TextBox3.Text = total      : Nilai Textbox3 sama dengan variable total



TextBox3.ForeColor = Color.Plum   : Nilai TextBox3.ForeColor akan mengubah warna variable

Tidak ada komentar:

Posting Komentar