Laman

Minggu, 27 Oktober 2013

Contoh Visual Basic Sederhana2

Pada tutorial kali ini, kita bahas bersama contoh program visual basic. Langkah-langkah nya sbb:
1. Buka Microsoft Visual Studio
2. Buka New>>Project
3. Beri nama project anda pada name, kemudian klik ok
4. Setelah itu maka akan keluar From1 di project kita, kemudian desain From tersebut dengan menggunakan Label, Textbox, Combobox, dan Botton yang dapat kata pilih pada proporties.
 5. Listing Program
 

Public Class latihan_di_bpc


    Private Sub KB_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KD.SelectedIndexChanged
        Dim p As String
        p = Microsoft.VisualBasic.Left(KD.Text, 2)
        If KD.Text = "LPB" Then
            Dim j As Integer
            For j = 1 To 3
                TB.Items.Add(p & "00" & j)
            Next
        ElseIf KD.Text = "CVB" Then
            Dim I As Integer
            For I = 1 To 3
                TB.Items.Add(p & "00" & I)
            Next

        ElseIf KD.Text = "STB" Then
            Dim U As Integer
            For U = 1 To 3
                TB.Items.Add(p & "00" & U)
            Next
        End If
    End Sub

    Private Sub latihan_di_bpc_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        KB.Items.Add("LPB")
        KB.Items.Add("CVB")
        KB.Items.Add("STB")

    End Sub

    Private Sub btnkeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnkeluar.Click
        End
    End Sub

    Private Sub TB_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TB.SelectedIndexChanged
        Select Case TB.Text

            Case Is = "LP001"
                NB.Text = "acer"
                HB.Text = "4000000"

            Case Is = "LP002"
                NB.Text = "lenovo"
                HB.Text = "5200000"

            Case Is = "LP003"
                NB.Text = "hp"
                HB.Text = "3500000"

            Case Is = "CV001"
                NB.Text = "canon"
                HB.Text = "1500000"

            Case Is = "CV002"
                NB.Text = "sony"
                HB.Text = "1000000"

            Case Is = "CV003"
                NB.Text = "Epson"
                HB.Text = "1200000"

            Case Is = "ST001"
                NB.Text = "philips"
                HB.Text = "1000000"

            Case Is = "ST002"
                NB.Text = "sAmsung"
                HB.Text = "1200000"

            Case Is = "ST003"
                NB.Text = "LG"
                HB.Text = "1500000"
        End Select
    End Sub


    Private Sub JB_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles JB.KeyPress
        If e.KeyChar = Chr(13) Then
            TOTh.Text = HB.Text * JB.Text
        End If
    End Sub

    Private Sub Btnproses_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnproses.Click
        kemb.Text = P.Text - TOTh.Text
    End Sub

    Private Sub btnhapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnhapus.Click
        KB.Text = ""
        TB.Text = ""
        NB.Text = ""
        HB.Text = ""
        JB.Text = ""
        TOTh.Text = ""
        P.Text = ""
        kemb.Text = ""
    End Sub
End Class

 6. Setelah selesai, tekan F5 untuk menjalankan programnya.
 Hasilnya

NOTE:
KB= Kode Barang
TB= Tipe Barang
NB= Nama Barang
HB= Harga Barang
JB= Jumlah Barang
TOTh= Total Harga
P= Pembayaran
Kemb= Kembalian
  •  Kode barang muncul pada saat program dijalankan
  •  Tipe barang muncul pada saat kode barang dipilih, dengan mengambil 2 karakter dari kiri tipe barang  dan loopingkan
  • Nama barang  dan harga barang  muncul pada saat  tipe barang dipilih
  • Jumlah dan pembayaran asumsikan sendiri
  • Total harga muncul pada saat enter di tekan
  • Pengembalian muncul pada saat proses

 

2 komentar: