Sabtu, 28 Januari 2012

Jawaban Soal No.3

Listing Programnya


Public Class Form1

    Private Sub btnlogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlogin.Click
        If password.Text = "1002269" Then
            menu_utama.show()
            Me.Hide()
        Else
            MsgBox("Maaf Password anda masih salah !!!")
        End If
    End Sub
    Private Sub btnkeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnkeluar.Click
        MsgBox("Anda yakin ingin keluar")
        End
    End Sub
End Class

Hasil Programnya


Listing Program Menu


Public Class Menu_utama
    Private Sub KeluarProgramToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KeluarProgramToolStripMenuItem.Click
        MsgBox("Anda yakin ingin keluar dari program ini!")
        End
    End Sub
    Private Sub DataGajiToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGajiToolStripMenuItem.Click
        data.Show()
        Me.Hide()
    End Sub
    Private Sub jam_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles jam.Tick
        Dim x As DateTime = Now
        waktu.Text = x.ToString("F")
    End Sub
End Class

Hasil Programnya
 Listing Program Data Gaji Karyawan




Public Class data

    Private Sub data_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        jabatan.Items.Add("Mandor")
        jabatan.Items.Add("Kepala Bagian")
        jabatan.Items.Add("Staff")
        status.Items.Add("Menikah")
        status.Items.Add("Belum Menikah")
        buat_tabel()
    End Sub
    Sub proses()
        If jabatan.Text = "Mandor" Then
            gapok.Text = "1750000"
            pajak.Text = 0.015 * Val(gapok.Text)
        ElseIf jabatan.Text = "Kepala Bagian" Then
            gapok.Text = "2500000"
            pajak.Text = 0.015 * Val(gapok.Text)
        ElseIf jabatan.Text = "Staff" Then
            gapok.Text = "1250000"
            pajak.Text = 0.015 * Val(gapok.Text)
        End If
        Select Case status.Text
            Case "Menikah" : tuis.Text = 0.09 * Val(gapok.Text)
            Case "Belum Menikah" : tuis.Text = 0
        End Select
        If anak.Text = "1" Then
            tunak.Text = 0.03 * Val(gapok.Text)
        ElseIf anak.Text = "2" Then
            tunak.Text = 0.07 * Val(gapok.Text)
        ElseIf anak.Text >= "2" Then
            tunak.Text = 0.07 * Val(gapok.Text)
        ElseIf anak.Text <= "1" Then
            tunak.Text = 0
        End If
        If jabatan.Text = "Mandor" Then
            If lembur.Text = "0" Then
                galem.Text = 0
            ElseIf lembur.Text = "1" Then
                galem.Text = 7500
            ElseIf lembur.Text >= "1" Then
                galem.Text = 7500 * Val(lembur.Text)
            End If
        ElseIf jabatan.Text = "Kepala Bagian" Then
            If lembur.Text = "0" Then
                galem.Text = 0
            ElseIf lembur.Text = "1" Then
                galem.Text = 10000
            ElseIf lembur.Text >= "1" Then
                galem.Text = 10000 * Val(lembur.Text)
            End If
        ElseIf jabatan.Text = "Staff" Then
            If lembur.Text = "0" Then
                galem.Text = 0
            ElseIf lembur.Text = "1" Then
                galem.Text = 5000
            ElseIf lembur.Text >= "1" Then
                galem.Text = 5000 * Val(lembur.Text)
            End If
        End If
        total.Text = Val(gapok.Text) + Val(tuis.Text) + Val(tunak.Text) + Val(galem.Text) - Val(pajak.Text)
    End Sub
    Sub buat_tabel()
        With LV
            .Columns.Add("Nama karyawan", 110, HorizontalAlignment.Left)
            .Columns.Add("Jabatan", 90, HorizontalAlignment.Left)
            .Columns.Add("Gaji Pokok", 80, HorizontalAlignment.Center)
            .Columns.Add("Status", 100, HorizontalAlignment.Left)
            .Columns.Add("Tunjangan Istri", 98, HorizontalAlignment.Center)
            .Columns.Add("Anak", 40, HorizontalAlignment.Center)
            .Columns.Add("Tunjangan Anak", 98, HorizontalAlignment.Center)
            .Columns.Add("Pajak", 55, HorizontalAlignment.Center)
            .Columns.Add("Lembur", 50, HorizontalAlignment.Center)
            .Columns.Add("Gaji Lembur/jam", 100, HorizontalAlignment.Center)
            .Columns.Add("Total Gaji", 90, HorizontalAlignment.Center)
            .View = View.Details
            .GridLines = True
            .FullRowSelect = True
        End With
    End Sub
    Sub isi_tabel()
        Dim lst As New ListViewItem
        lst.Text = nama.Text
        lst.SubItems.Add(jabatan.Text)
        lst.SubItems.Add(gapok.Text)
        lst.SubItems.Add(status.Text)
        lst.SubItems.Add(tuis.Text)
        lst.SubItems.Add(anak.Text)
        lst.SubItems.Add(tunak.Text)
        lst.SubItems.Add(pajak.Text)
        lst.SubItems.Add(lembur.Text)
        lst.SubItems.Add(galem.Text)
        lst.SubItems.Add(total.Text)
        LV.Items.Add(lst)
    End Sub
    Private Sub jabatan_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles jabatan.SelectedIndexChanged
        Call proses()
    End Sub
    Private Sub status_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles status.SelectedIndexChanged
        Call proses()
    End Sub
    Private Sub lembur_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lembur.TextChanged
        Call proses()
    End Sub
    Private Sub anak_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles anak.TextChanged
        Call proses()
    End Sub
    Private Sub btnsimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsimpan.Click
        isi_tabel()
    End Sub
    Private Sub btnbersih_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbersih.Click
        nama.Text = ""

Jawaban Soal No.2

Kasus: Jawaban Soal no.2klik disini


Listing Program


Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        kode.Items.Add("TS001")
        kode.Items.Add("TS002")
        kode.Items.Add("VG001")
        kode.Items.Add("VG002")
        buat_tabel()
    End Sub
    Sub cek()
        Dim x As String
        x = Microsoft.VisualBasic.Left(kode.Text, 2)
        If x = "TS" Then
            merk.Text = "Toshiba"
        ElseIf x = "VG" Then
            merk.Text = "V-Gen"
        End If
        x = Microsoft.VisualBasic.Mid(kode.Text, 3, 3)
        If x = "001" Then
            nama.Text = "Flasdisk 4GB"
        ElseIf x = "002" Then
            nama.Text = "Flasdisk 2GB"
        End If
        If kode.Text = "TS001" Then
            harga.Text = 105000
        ElseIf kode.Text = "TS002" Then
            harga.Text = 75000
        End If
        If kode.Text = "VG001" Then
            harga.Text = 90000
        ElseIf kode.Text = "VG002" Then
            harga.Text = 6000
        End If
    End Sub
    Sub buat_tabel()
        With LV
            .Columns.Add("No.pembelian", 85, HorizontalAlignment.Center)
            .Columns.Add("Kode Barang", 90, HorizontalAlignment.Center)
            .Columns.Add("Nama Barang", 80, HorizontalAlignment.Left)
            .Columns.Add("Merk", 70, HorizontalAlignment.Center)
            .Columns.Add("Harga", 75, HorizontalAlignment.Center)
            .Columns.Add("Jumlah Beli", 90, HorizontalAlignment.Center)
            .Columns.Add("Total Harga", 90, HorizontalAlignment.Center)
            .View = View.Details
            .GridLines = True
            .FullRowSelect = True
        End With
    End Sub
    Sub isi_tabel()
        Dim lst As New ListViewItem
        lst.Text = no.Text
        lst.SubItems.Add(kode.Text)
        lst.SubItems.Add(nama.Text)
        lst.SubItems.Add(merk.Text)
        lst.SubItems.Add(harga.Text)
        lst.SubItems.Add(jumlah.Text)
        lst.SubItems.Add(total.Text)
        LV.Items.Add(lst)
    End Sub
    Private Sub kode_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles kode.SelectedIndexChanged
        Call cek()
    End Sub
    Private Sub jumlah_keypress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles jumlah.KeyPress
        Dim tombol As Integer = Asc(e.KeyChar)
        If tombol = 13 Then
            cek()
            total.Text = Val(harga.Text) * Val(jumlah.Text)
        End If
    End Sub
    Private Sub btnsimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsimpan.Click
        isi_tabel()
    End Sub
    Private Sub btnbersih_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbersih.Click
        no.Text = ""
        kode.Text = ""
        nama.Text = ""
        merk.Text = ""
        harga.Text = ""
        jumlah.Text = ""
        total.Text = ""
        no.Focus()
    End Sub
    Private Sub btnhapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnhapus.Click
        LV.Items.Clear()
    End Sub
    Private Sub btnpilih_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnpilih.Click
        LV.Items.Remove(LV.SelectedItems(0))
    End Sub
    Private Sub btnkeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnkeluar.Click
        End
    End Sub
End Class


Hasil Program


 Catatan :
Fungsi Tombol
* Simpan ke ListView : memasukkan data ke dalam tabel
* Bersih   : menghapus data
* Hapus Semua Data  : menghapus semua data yang ada di tabel
* Hapus Data yang di pilih   : menghapus salah satu data yang dipilih pada di tabel
* Keluar Program  : keluar dari program

Selasa, 17 Januari 2012

Penggunaan ListView pada VB.Net

http://mesran.wordpress.com/2012/01/26/soal-quiz-online-hari-kamis/
Tampilan Formnya...

Listing Programnya

Public Class Form1
Sub proses1()
Dim x As String
x = Microsoft.VisualBasic.Left(npm.Text, 2)
If x = "10" Then
tahun.Text = "2010"
ElseIf x = "00" Then
tahun.Text = "2009"
End If
x = Microsoft.VisualBasic.Mid(npm.Text, 3, 1)
If x = "1" Then
jenjang.Text = "Diploma I"
ElseIf x = "2" Then
jenjang.Text = "Diploma III"
ElseIf x = "3" Then
jenjang.Text = "Strata I"
End If
x = Microsoft.VisualBasic.Mid(npm.Text, 4, 2)
If x = "01" Then
jurusan.Text = "Manajemen Informatika"
ElseIf x = "02" Then
jurusan.Text = "Sistem Informasi"
ElseIf x = "03" Then
jurusan.Text = "Akuntansi"
End If
End Sub
Sub proses()
If nilai_angka.Text >= 80 Then
nilai_huruf.Text = "A"
ElseIf nilai_angka.Text >= 65 Then
nilai_huruf.Text = "B"
ElseIf nilai_angka.Text >= 55 Then
nilai_huruf.Text = "C"
ElseIf nilai_angka.Text >= 45 Then
nilai_huruf.Text = "D"
Else
nilai_huruf.Text = "E"
End If
End Sub
Private Sub npm_keypress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles npm.KeyPress
Dim tombol As Integer = Asc(e.KeyChar)
If tombol = 13 Then
proses1()
End If
End Sub
Private Sub na_keypress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles nilai_angka.KeyPress
Dim tombol As Integer = Asc(e.KeyChar)
If tombol = 13 Then
proses()
End If
End Sub
Sub buat_Tabel()
With LV
.Columns.Add("NPM", 60, HorizontalAlignment.Left)
.Columns.Add("Nama", 100, HorizontalAlignment.Left)
.Columns.Add("Jurusan", 130, HorizontalAlignment.Left)
.Columns.Add("Jenjang", 75, HorizontalAlignment.Center)
.Columns.Add("Tahun Masuk", 85, HorizontalAlignment.Center)
.Columns.Add("Nilai Angka", 80, HorizontalAlignment.Center)
.Columns.Add("Niai Huruf", 80, HorizontalAlignment.Center)
.View = View.Details
.GridLines = True
.FullRowSelect = True
End With
End Sub
Sub isitabel()
Dim lst As New ListViewItem
lst.Text = npm.Text
lst.SubItems.Add(nama.Text)
lst.SubItems.Add(jurusan.Text)
lst.SubItems.Add(jenjang.Text)
lst.SubItems.Add(tahun.Text)
lst.SubItems.Add(nilai_angka.Text)
lst.SubItems.Add(nilai_huruf.Text)
LV.Items.Add(lst)
End Sub

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

Private Sub btnsimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsimpan.Click
isitabel()
End Sub

Private Sub btnbersih_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbersih.Click
npm.Text = ""
nama.Text = ""
jurusan.Text = ""
jenjang.Text = ""
tahun.Text = ""
nilai_angka.Text = ""
nilai_huruf.Text = ""
npm.Focus()
End Sub

Private Sub btnhapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnhapus.Click
LV.Items.Clear()
End Sub

Private Sub btndata_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndata.Click
LV.Items.Remove(LV.SelectedItems(0))
End Sub

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

Private Sub waktu_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles waktu.Tick
Dim waktu As DateTime = Now()
jam.Text = waktu.ToString("F")
End Sub
End Class


Catatan :

Fungsi pada tombol :

* Simpan ke ListView       :  memasukkan data ke dalam Tabel
* Bersih                            :  menghapus data yang telah kita buat
* Hapus Data yang di pilih : menghapus data yang kita inginkan yang berada di dalam tabel
* hapus Semua data          : menghapus semua data yang ada di tabel
* Keluar                           : keluar dari program