Tuesday, 27 October 2015

Cara Membuat Kalkulator Dengan Button Di Visual Basic 2010

Langsung saja pada praktek , Pertama kita buat desain nya dulu seperti itu ,

Jangan merubah bagian property
Setelah desainnya berhasil , sekarang kita akan masuk ke dalam bagian koding abra kadabranya , Tinggal copy paste saja yah gan , biar cepet .

Public Class Frm_Kalkulator
    Dim nilai1 As Double
    Dim hasil As Double
    Dim rumus As String

    Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
        nilai1 = Val(angka.Text)
        rumus = "+"
        angka.Text = ""
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        angka.Text = angka.Text & "1"

    End Sub

    Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click
        angka.Text = angka.Text & "2"
    End Sub

    Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
        angka.Text = angka.Text & "3"
    End Sub

    Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
        angka.Text = angka.Text & "4"
    End Sub

    Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
        angka.Text = angka.Text & "5"
    End Sub

    Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
        angka.Text = angka.Text & "6"
    End Sub

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

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

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

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

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

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If angka.Text.Length <> 0 Then
            angka.Text = angka.Text.Remove(angka.TextLength - 1, 1)

        End If
    End Sub

    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        nilai1 = Val(angka.Text)
        rumus = "-"
        angka.Text = Nothing
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        nilai1 = Val(angka.Text)
        rumus = "/"
        angka.Text = Nothing
    End Sub

    Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click
        nilai1 = Val(angka.Text)
        rumus = "x"
        angka.Text = Nothing
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Select Case rumus
            Case "+"
                hasil = nilai1 + Val(angka.Text)
                angka.Text = hasil
            Case "-"
                hasil = nilai1 - Val(angka.Text)
                angka.Text = hasil
            Case "/"
                hasil = nilai1 / Val(angka.Text)
                angka.Text = hasil
            Case "x"
                hasil = nilai1 * Val(angka.Text)
                angka.Text = hasil


        End Select
    End Sub

    Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button18.Click
        angka.Text = ""
    End Sub

    Private Sub Button19_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button19.Click
        Close()
    End Sub

 
End Class
Bagaimana cara masuk ke pengkodingan di visual basic 2010 ? caranya mudah gan , tinggal klik saja dua kali di area mana saja asal jangan di area tombol , kotak warna putih , label (tulisan) .

It's Edit time bibeh !!!

Ganti script di bawah ini :

Public Class Frm_Kalkulator
    Dim nilai1 As Double
    Dim hasil As Double
    Dim rumus As String
Menjadi

Public Class Form1
  Dim nilai1 As Double
    Dim hasil As Double
    Dim rumus As String
 Sekarang ganti semua tulisan angka dengan TextBox1

Nah , Sekarang coba jalankan aplikasinya . sengaja tutorialnya tidak se detail pembahasan yang dulu biar agan bisa nanya :D , jadi disini kita bisa tuker ilmu gitu . jangan hanya jadi silent reader dan copy paste langsung hilang tanpa jejak .

Any Question ?
Previous Post
Next Post
Related Posts

1 comment:

  1. Mau tanya min cara masukan kodingnya di dabel klik di bagian mananya ya

    ReplyDelete