Assalamualaikum! Pada artikel kali ini saya akan membuat aplikasi sederhana absensi menggunakan Visual Studio code behind VB.Net, Visual Studio yang saya gunakan adalah versi 2008. Aplikasi ini menampilkan CSV (Comma Separated Value) yaitu suatu format data dalam basis data di mana setiap record dipisahkan dengan tanda koma (,) atau titik koma (;). Selain sederhana, format ini dapat dibuka dengan berbagai text-editor seperti Notepad, Wordpad, bahkan Microsoft Excel. Basis data dalam aplikasi absensi yang saya buat ini dibuka dengan Microsoft Excel. Cekidot!
Pertama kita buat dulu database nya menggunakan Ms. Excel dengan nama Absensi VB.csv, kemudian isi field database nya sebagai berikut:
Setelah selesai membuat database nya, kita move ke Visual Studio. Langkah awalnya sama seperti biasa pada artikel saya sebelumnya lalu buat form absen seperti ini:
Form nya terdiri dari:
Jenis Komponen | Name | Text |
Label | Label1 | A B S E N S I |
Label | Label2 | LAB. PENGANTAR PEMROGRAMAN BISNIS KELAS C |
Label | Label3 | NPM |
Label | Label4 | Nama |
Label | Label5 | Kehadiran |
Label | Label6 | Hadir |
Label | Label7 | Sakit |
Label | Label8 | Izin |
Label | Label9 | Alpa |
Label | Label10, Label11, Label12, Label13 | Menyesuaikan dengan input dan code |
TextBox | txtNPM | – |
TextBox | TxtNama | – |
ComboBox | cmbKehadiran | Hadir
Tidak Hadir
|
GroupBox | GroupBox1 | Alasan Ketidak Hadiran |
GroupBox | GroupBox2 | Ringkasan Absen |
RadioButton | radioSakit | Sakit |
RadioButton | radioIzin | Izin |
RadioButton | radioAlpa | Alpa |
Button | btnSimpan | Simpan |
Button | btnTambah | Tambah |
ListBox | ListBox1 | – |
Jika telah lengkap semua komponen yang dibutukan, saatnya coding! Isi code berikut pada:
- Form dengan prosedur Activated
Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
On Error Resume Next
Dim Var6 As Object
Dim Var5 As Object
Dim Var4 As Object
Dim Var3 As Object
Dim Var2 As Object
Dim Var1 As Object
Dim noFile As Short
noFile = FreeFile()
On Error Resume Next
Dim Var6 As Object
Dim Var5 As Object
Dim Var4 As Object
Dim Var3 As Object
Dim Var2 As Object
Dim Var1 As Object
Dim noFile As Short
noFile = FreeFile()
FileOpen(noFile, “C:\Users\w7\Documents\Visual Studio 2008\Projects\UAS VB – Vina Noor Savira\absensi vb.csv”, OpenMode.Input)
Do While Not EOF(noFile)
Input(1, Var1)
Input(1, Var2)
Input(1, Var3)
Input(1, Var4)
Input(1, Var5)
Input(1, Var6)
ListBox1.Items.Add(Var1 & “—” & Var2 & “—” & Var3 & “—” & Var4 & “—” & Var5 & “—” & Var6)
Loop
FileClose(noFile)
Do While Not EOF(noFile)
Input(1, Var1)
Input(1, Var2)
Input(1, Var3)
Input(1, Var4)
Input(1, Var5)
Input(1, Var6)
ListBox1.Items.Add(Var1 & “—” & Var2 & “—” & Var3 & “—” & Var4 & “—” & Var5 & “—” & Var6)
Loop
FileClose(noFile)
- Form dengan prosedur Load
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
txtNPM.Text = “”
txtNama.Text = “”
cmbKehadiran.Text = “”
Label10.Text = 0
Label11.Text = 0
Label12.Text = 0
Label13.Text = 0
End Sub
txtNPM.Text = “”
txtNama.Text = “”
cmbKehadiran.Text = “”
Label10.Text = 0
Label11.Text = 0
Label12.Text = 0
Label13.Text = 0
End Sub
- cmbKehadiran
Private Sub cmbKehadiran_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbKehadiran.SelectedIndexChanged
If cmbKehadiran.Text = “Hadir” Then
radioSakit.Enabled = False
radioIzin.Enabled = False
radioAlpa.Enabled = False
Label10.Text = Val(Label10.Text) + 1
Else
radioSakit.Enabled = True
radioIzin.Enabled = True
radioAlpa.Enabled = True
End If
End Sub
If cmbKehadiran.Text = “Hadir” Then
radioSakit.Enabled = False
radioIzin.Enabled = False
radioAlpa.Enabled = False
Label10.Text = Val(Label10.Text) + 1
Else
radioSakit.Enabled = True
radioIzin.Enabled = True
radioAlpa.Enabled = True
End If
End Sub
- radioSakit
Private Sub radioSakit_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radioSakit.CheckedChanged
If radioSakit.Checked = True Then
Label11.Text = Val(Label11.Text) + 1
radioIzin.Enabled = False
radioAlpa.Enabled = False
Else
Label11.Text = Val(Label11.Text) + 0
End If
End Sub
If radioSakit.Checked = True Then
Label11.Text = Val(Label11.Text) + 1
radioIzin.Enabled = False
radioAlpa.Enabled = False
Else
Label11.Text = Val(Label11.Text) + 0
End If
End Sub
- radioIzin
Private Sub radioIzin_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radioIzin.CheckedChanged
If radioIzin.Checked = True Then
Label12.Text = Val(Label12.Text) + 1
radioSakit.Enabled = False
radioAlpa.Enabled = False
Else
Label12.Text = Val(Label12.Text) + 0
End If
End Sub
If radioIzin.Checked = True Then
Label12.Text = Val(Label12.Text) + 1
radioSakit.Enabled = False
radioAlpa.Enabled = False
Else
Label12.Text = Val(Label12.Text) + 0
End If
End Sub
- radioAlpa
Private Sub radioAlpa_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radioAlpa.CheckedChanged
If radioAlpa.Checked = True Then
Label13.Text = Val(Label13.Text) + 1
radioIzin.Enabled = False
radioSakit.Enabled = False
Else
Label13.Text = Val(Label13.Text) + 0
End If
End Sub
If radioAlpa.Checked = True Then
Label13.Text = Val(Label13.Text) + 1
radioIzin.Enabled = False
radioSakit.Enabled = False
Else
Label13.Text = Val(Label13.Text) + 0
End If
End Sub
- btnSimpan
Private Sub btnSimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSimpan.Click
Dim Var6 As Object
Dim Var5 As Object
Dim Var4 As Object
Dim Var3 As Object
Dim Var2 As Object
Dim Var1 As Object
Dim noFile As Short
noFile = FreeFile()
FileOpen(noFile, “C:\Users\w7\Documents\Visual Studio 2008\Projects\UAS VB – Vina Noor Savira\absensi vb.csv”, OpenMode.Append)
Var1 = txtNPM.Text
Var2 = txtNama.Text
Var3 = Label10.Text
Var4 = Label11.Text
Var5 = Label12.Text
Var6 = Label13.Text
Dim Var6 As Object
Dim Var5 As Object
Dim Var4 As Object
Dim Var3 As Object
Dim Var2 As Object
Dim Var1 As Object
Dim noFile As Short
noFile = FreeFile()
FileOpen(noFile, “C:\Users\w7\Documents\Visual Studio 2008\Projects\UAS VB – Vina Noor Savira\absensi vb.csv”, OpenMode.Append)
Var1 = txtNPM.Text
Var2 = txtNama.Text
Var3 = Label10.Text
Var4 = Label11.Text
Var5 = Label12.Text
Var6 = Label13.Text
ListBox1.Items.Add(Var1 & “—” & Var2 & “—” & Var3 & “—” & Var4 & “—” & Var5 & “—” & Var6)
WriteLine(1, Var1, Var2, Var3, Var4, Var5, Var6)
FileClose(1)
End Sub
WriteLine(1, Var1, Var2, Var3, Var4, Var5, Var6)
FileClose(1)
End Sub
- btnTambah
Private Sub btnTambah_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTambah.Click
radioSakit.Checked = False
radioIzin.Checked = False
radioAlpa.Checked = False
txtNPM.Text = “”
txtNama.Text = “”
cmbKehadiran.Text = “”
Label10.Text = 0
Label11.Text = 0
Label12.Text = 0
Label13.Text = 0
txtNPM.Focus()
End Sub
End Class
radioSakit.Checked = False
radioIzin.Checked = False
radioAlpa.Checked = False
txtNPM.Text = “”
txtNama.Text = “”
cmbKehadiran.Text = “”
Label10.Text = 0
Label11.Text = 0
Label12.Text = 0
Label13.Text = 0
txtNPM.Focus()
End Sub
End Class
Nah, jika semua code komponen yang dibutuhkan sudah dilengkapi, saat dijalankan akan tampil seperti ini:
ConversionConversion EmoticonEmoticon