Pada tutor kali ini saya
akan mencoba lagi untuk membuat program sederhana Membuat Penghitungan Gaji
Karyawan menggunakan Visual Basic. Pada codenya nanti dengan menambahkan FUNCTION, Sehingga hasil yang akan diperoleh adalah seperti berikut :
Perhatikan hasil gambar
di atas!
operator hanya mengimputkan nilai untuk Gaji pokok dan Tunjangan beras, maka untuk pajak, gaji bersih, Total gaji dan Rata-rata langung mendapatkan hasilnya. Itulah Kegunaan dari FUNCTION.
operator hanya mengimputkan nilai untuk Gaji pokok dan Tunjangan beras, maka untuk pajak, gaji bersih, Total gaji dan Rata-rata langung mendapatkan hasilnya. Itulah Kegunaan dari FUNCTION.
Sekarang mari kita
cobakan :
Komponen-komponen yang akan di pakai
adalah : 1 buah Form, 12 buah label. 22 Text Box dan 2 buah
ComandButton.Kemudian Ganti Caption pada label dengan nama tersendiri, kemudian
CommanButton ganti dengan TUTUP dan Ulangi/Bersih.
Pada Text Box Name-nya
terserah kepada anda. Hasil akhirnya Kopas atau ketik code di bawah ini :
Private Sub cmdProses_Click()
txtpajak.Text = 10 / 100 * (Val(TxtGAPOK.Text) + Val(txtTb.Text))
txtgaber.Text = Val(TxtGAPOK.Text) + Val(txtTb.Text) -
Val(txtpajak.Text)
End Sub
Private
Sub cmdUlangi_Click()
Bersih
End Sub
Private Sub cmlTutup_Click()
Unload Me
'Bisa juga di pakai "End
'Bisa juga di pakai "End
End Sub
Private
Sub Bersih()
txtgapok1.Text = ""
txtgapok2.Text = ""
txtgapok3.Text = ""
txtgapok4.Text = ""
txtgapok5.Text = ""
txttuber1.Text = ""
txttuber2.Text = ""
txttuber3.Text = ""
txttuber4.Text = ""
txttuber5.Text = ""
txtpajak1.Text = ""
txtpajak2.Text = ""
txtpajak3.Text = ""
txtpajak4.Text = ""
txtpajak5.Text = ""
txtgaber1.Text = ""
txtgaber2.Text = ""
txtgaber3.Text = ""
txtgaber4.Text = ""
txtgaber5.Text = ""
txttotal.Text = ""
txtratarata.Text = ""
End Sub
Private
Sub txtgaber1_Change()
txttotal.Text = TOTAL(Val(txtgaber1.Text), Val(txtgaber2.Text),
Val(txtgaber3.Text), Val(txtgaber4.Text), Val(txtgaber5.Text))
txtratarata.Text = RATA2(Val(txttotal.Text))
End Sub
Private
Sub txtgaber2_Change()
txttotal.Text = TOTAL(Val(txtgaber1.Text), Val(txtgaber2.Text),
Val(txtgaber3.Text), Val(txtgaber4.Text), Val(txtgaber5.Text))
txtratarata.Text = RATA2(Val(txttotal.Text))
End Sub
Private
Sub txtgaber3_Change()
txttotal.Text = TOTAL(Val(txtgaber1.Text), Val(txtgaber2.Text), Val(txtgaber3.Text),
Val(txtgaber4.Text), Val(txtgaber5.Text))
txtratarata.Text = RATA2(Val(txttotal.Text))
End Sub
Private
Sub txtgaber4_Change()
txttotal.Text = TOTAL(Val(txtgaber1.Text), Val(txtgaber2.Text),
Val(txtgaber3.Text), Val(txtgaber4.Text), Val(txtgaber5.Text))
txtratarata.Text = RATA2(Val(txttotal.Text))
End Sub
Private
Sub txtgaber5_Change()
txttotal.Text = TOTAL(Val(txtgaber1.Text), Val(txtgaber2.Text),
Val(txtgaber3.Text), Val(txtgaber4.Text), Val(txtgaber5.Text))
txtratarata.Text = RATA2(Val(txttotal.Text))
End Sub
Private
Sub txtgapok1_Change()
txtpajak1.Text = PAJAK(Val(txtgapok1.Text), Val(txttuber1.Text))
txtgaber1.Text = GABER(Val(txtgapok1.Text), Val(txttuber1.Text),
Val(txtpajak1.Text))
End Sub
Private
Function PAJAK(GAPOK As Single, TUBER As Single) As Single
PAJAK = 10 / 100 * (GAPOK + TUBER)
End
Function
Private
Function GABER(GAPOK As Single, TUBER As Single, PAJAK) As Single
GABER = (GAPOK + TUBER) - PAJAK
End
Function
Private
Sub txtgapok2_Change()
txtpajak2.Text = PAJAK(Val(txtgapok2.Text), Val(txttuber2.Text))
txtgaber2.Text = GABER(Val(txtgapok2.Text), Val(txttuber2.Text),
Val(txtpajak2.Text))
End Sub
Private
Sub txtgapok3_Change()
txtpajak3.Text = PAJAK(Val(txtgapok3.Text), Val(txttuber3.Text))
txtgaber3.Text = GABER(Val(txtgapok3.Text), Val(txttuber3.Text),
Val(txtpajak3.Text))
End Sub
Private
Sub txtgapok4_Change()
txtpajak4.Text = PAJAK(Val(txtgapok4.Text), Val(txttuber4.Text))
txtgaber4.Text = GABER(Val(txtgapok4.Text), Val(txttuber4.Text),
Val(txtpajak4.Text))
End Sub
Private
Sub txtgapok5_Change()
txtpajak5.Text = PAJAK(Val(txtgapok5.Text), Val(txttuber5.Text))
txtgaber5.Text = GABER(Val(txtgapok5.Text), Val(txttuber5.Text),
Val(txtpajak5.Text))
End Sub
Private
Sub txttuber1_Change()
txtpajak1.Text = PAJAK(Val(txtgapok1.Text), Val(txttuber1.Text))
txtgaber1.Text = GABER(Val(txtgapok1.Text), Val(txttuber1.Text),
Val(txtpajak1.Text))
End Sub
Private Sub txttuber2_Change()
txtpajak2.Text = PAJAK(Val(txtgapok2.Text), Val(txttuber2.Text))
txtgaber2.Text = GABER(Val(txtgapok2.Text), Val(txttuber2.Text),
Val(txtpajak2.Text))
End Sub
Private
Sub txttuber3_Change()
txtpajak3.Text = PAJAK(Val(txtgapok3.Text), Val(txttuber3.Text))
txtgaber3.Text = GABER(Val(txtgapok3.Text), Val(txttuber3.Text),
Val(txtpajak3.Text))
End Sub
Private
Sub txttuber4_Change()
txtpajak4.Text = PAJAK(Val(txtgapok4.Text), Val(txttuber4.Text))
txtgaber4.Text = GABER(Val(txtgapok4.Text), Val(txttuber4.Text),
Val(txtpajak4.Text))
End Sub
Private
Sub txttuber5_Change()
txtpajak5.Text = PAJAK(Val(txtgapok5.Text), Val(txttuber5.Text))
txtgaber5.Text = GABER(Val(txtgapok5.Text), Val(txttuber5.Text),
Val(txtpajak4.Text))
End Sub
Private
Function TOTAL(GABER1 As Single, GABER2 As Single, GABER3 As Single, GABER4 As
Single, GABER5 As Single) As Single
TOTAL = GABER1 + GABER2 + GABER3 + GABER4 + GABER5
End
Function
Private
Function RATA2(TOTAL As Single) As Single
RATA2 = TOTAL / 5
End
Function
Private
Function RATARATA(GABER1 As Single, GABER2 As Single, BAGER3 As Single) As
Single
RATARATA = (GABER1 + GABER2 + GABER3) / 3
End
Function
1 comments:
wah mas terima kasih banyak, kebetulan dapet tugas kuliah yg hampir mirip dengan ini
Posting Komentar