Buat Form program di visual basic seperti gambar di atas.
setelah mendesain form seperti gambar di atas, silahkan anda mengatur beberapa bagian pada properti seperti pada label (text), combo box(name), text box(name), button(name & text). lihat pada gambar berikut ini :
setelah menentukan properties toolbox pada form, silahkan anda memulai dengan mengetik listing program pada jendela pemograman visual basic.
listing program:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
golongan.Items.Add("IIIA")
golongan.Items.Add("IIIB")
golongan.Items.Add("IIIC")
status.Items.Add("Menikah")
status.Items.Add("Belum Menikah")
nip.Items.Add("AB6001")
nip.Items.Add("AB6002")
nip.Items.Add("AB6003")
nip.Items.Add("AB6004")
End Sub
Private Sub golongan_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles golongan.SelectedIndexChanged
If golongan.Text = "IIIA" Then
gaji.Text = 4500000
ElseIf golongan.Text = "IIIB" Then
gaji.Text = 3000000
ElseIf golongan.Text = "IIIC" Then
gaji.Text = 2500000
Else
gaji.Text = 0
End If
End Sub
Private Sub btnproses_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnproses.Click
tgaji.Text = Val(tkeluarga.Text) + Val(gaji.Text)
End Sub
Private Sub btnkeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnkeluar.Click
Me.Close()
End Sub
Private Sub status_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles status.SelectedIndexChanged
If status.Text = "Menikah" Then
tkeluarga.Text = 0.15 * gaji.Text
ElseIf status.Text = "Belum Menikah" Then
tkeluarga.Text = 0.25 * gaji.Text
Else
tkeluarga.Text = 0
End If
End Sub
Private Sub nama_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nama.SelectedIndexChanged
End Sub
Private Sub nip_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nip.SelectedIndexChanged
If nip.Text = "AB6001" Then
nama.Text = "Zulfan Anugerah Zega"
ElseIf nip.Text = "AB6002" Then
nama.Text = "Irwan Gulo"
ElseIf nip.Text = "AB6003" Then
nama.Text = "Melinus Laoli"
ElseIf nip.Text = "AB6004" Then
nama.Text = "Toni Sartana Sianturi"
Else
nama.Text = 0
End If
End Sub
Private Sub btnhapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnhapus.Click
nip.Text = ""
nama.Text = ""
golongan.Text = ""
gaji.Text = ""
status.Text = ""
tkeluarga.Text = ""
tgaji.Text = ""
End Sub
Private Sub tkeluarga_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tkeluarga.TextChanged
End Sub
End Class
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
golongan.Items.Add("IIIA")
golongan.Items.Add("IIIB")
golongan.Items.Add("IIIC")
status.Items.Add("Menikah")
status.Items.Add("Belum Menikah")
nip.Items.Add("AB6001")
nip.Items.Add("AB6002")
nip.Items.Add("AB6003")
nip.Items.Add("AB6004")
End Sub
Private Sub golongan_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles golongan.SelectedIndexChanged
If golongan.Text = "IIIA" Then
gaji.Text = 4500000
ElseIf golongan.Text = "IIIB" Then
gaji.Text = 3000000
ElseIf golongan.Text = "IIIC" Then
gaji.Text = 2500000
Else
gaji.Text = 0
End If
End Sub
Private Sub btnproses_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnproses.Click
tgaji.Text = Val(tkeluarga.Text) + Val(gaji.Text)
End Sub
Private Sub btnkeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnkeluar.Click
Me.Close()
End Sub
Private Sub status_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles status.SelectedIndexChanged
If status.Text = "Menikah" Then
tkeluarga.Text = 0.15 * gaji.Text
ElseIf status.Text = "Belum Menikah" Then
tkeluarga.Text = 0.25 * gaji.Text
Else
tkeluarga.Text = 0
End If
End Sub
Private Sub nama_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nama.SelectedIndexChanged
End Sub
Private Sub nip_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nip.SelectedIndexChanged
If nip.Text = "AB6001" Then
nama.Text = "Zulfan Anugerah Zega"
ElseIf nip.Text = "AB6002" Then
nama.Text = "Irwan Gulo"
ElseIf nip.Text = "AB6003" Then
nama.Text = "Melinus Laoli"
ElseIf nip.Text = "AB6004" Then
nama.Text = "Toni Sartana Sianturi"
Else
nama.Text = 0
End If
End Sub
Private Sub btnhapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnhapus.Click
nip.Text = ""
nama.Text = ""
golongan.Text = ""
gaji.Text = ""
status.Text = ""
tkeluarga.Text = ""
tgaji.Text = ""
End Sub
Private Sub tkeluarga_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tkeluarga.TextChanged
End Sub
End Class
Hasilnya seperti pada gambar sebagai berikut :