You are on page 1of 6

D:\Data Kuliah Semester 4 (4MTI1)\Pemrograman Visual\Latihan UTS VB.

vb

07 April 2015 19:02

Public Class Form1


Private Structure mahasiswa
Dim nama As String
Dim nim As String
Dim jurusan As String
Dim semester As String
Dim tanggal As String
Dim bulan As String
Dim tahun As String
End Structure
Dim j As String
Dim sem, i, indeks, lebar, tinggi, cetak As Integer
Dim data() As mahasiswa
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load
indeks = 1
cetak = 0
sem = 0
ReDim data(indeks)
lebar = 411
tinggi = 315
Me.Width = lebar
Me.Height = tinggi
cmb_bulan.Enabled = False
cmb_tgl.Enabled = False
btn_cetak.Enabled = False
lbl_cetak.Visible = False
cmb_data.Items.Clear()
cmb_data.Visible = False
btn_ok.Visible = False
btn_cancel.Visible = False
panel_hasil.Visible = False
For i = 1990 To 2015
cmb_tahun.Items.Add(i)
Next i
End Sub
Private Sub rdb_1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles rdb_1.CheckedChanged
sem = 1
End Sub
Private Sub rdb_2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles rdb_2.CheckedChanged
sem = 2
End Sub
Private Sub rdb_3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles rdb_3.CheckedChanged
sem = 3
End Sub
Private Sub rdb_4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles rdb_4.CheckedChanged
-1-

D:\Data Kuliah Semester 4 (4MTI1)\Pemrograman Visual\Latihan UTS VB.vb

07 April 2015 19:02

sem = 4
End Sub
Private Sub rdb_5_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles rdb_5.CheckedChanged
sem = 5
End Sub
Private Sub rdb_6_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles rdb_6.CheckedChanged
sem = 6
End Sub
Private Sub rdb_7_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles rdb_7.CheckedChanged
sem = 7
End Sub
Private Sub rdb_8_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles rdb_8.CheckedChanged
sem = 8
End Sub
Private Sub cmb_tahun_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmb_tahun.SelectedIndexChanged
cmb_bulan.Items.Clear()
If CInt(cmb_tahun.Text) Mod 400 = 0 Then
'Sudah Pasti Tahun Kabisat
For i = 1 To 12
cmb_bulan.Items.Add(i)
Next i
cmb_bulan.Enabled = True
j = "kabisat"
ElseIf CInt(cmb_tahun.Text) Mod 400 <> 0 Then
If CInt(cmb_tahun.Text) Mod 100 = 0 Then
'Sudah Pasti Bukan Kabisat
For i = 1 To 12
cmb_bulan.Items.Add(i)
Next i
cmb_bulan.Enabled = True
j = "bukan kabisat"
ElseIf CInt(cmb_tahun.Text) Mod 100 <> 0 Then
If CInt(cmb_tahun.Text) Mod 4 = 0 Then
'Tahun Kabisat
For i = 1 To 12
cmb_bulan.Items.Add(i)
Next i
cmb_bulan.Enabled = True
j = "kabisat"
ElseIf CInt(cmb_tahun.Text) Mod 4 <> 0 Then
'Bukan Tahun Kabisat
For i = 1 To 12
cmb_bulan.Items.Add(i)
Next i
-2-

D:\Data Kuliah Semester 4 (4MTI1)\Pemrograman Visual\Latihan UTS VB.vb

07 April 2015 19:02

cmb_bulan.Enabled = True
j = "bukan kabisat"
End If
End If
End If
End Sub
Private Sub cmb_bulan_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmb_bulan.SelectedIndexChanged
cmb_tgl.Items.Clear()
If j = "kabisat" Then
If cmb_bulan.Text = "2" Then
For i = 1 To 29
cmb_tgl.Items.Add(i)
Next i
cmb_tgl.Enabled = True
ElseIf cmb_bulan.Text = "1" Or cmb_bulan.Text = "3" Or cmb_bulan.Text = "5" Or
cmb_bulan.Text = "7" Or cmb_bulan.Text = "8" Or cmb_bulan.Text = "10" Or
cmb_bulan.Text = "12" Then
For i = 1 To 31
cmb_tgl.Items.Add(i)
Next i
cmb_tgl.Enabled = True
ElseIf cmb_bulan.Text = "4" Or cmb_bulan.Text = "6" Or cmb_bulan.Text = "9" Or
cmb_bulan.Text = "11" Then
For i = 1 To 30
cmb_tgl.Items.Add(i)
Next i
cmb_tgl.Enabled = True
End If
ElseIf j = "bukan kabisat" Then
If cmb_bulan.Text = "2" Then
For i = 1 To 28
cmb_tgl.Items.Add(i)
Next i
cmb_tgl.Enabled = True
ElseIf cmb_bulan.Text = "1" Or cmb_bulan.Text = "3" Or cmb_bulan.Text = "5" Or
cmb_bulan.Text = "7" Or cmb_bulan.Text = "8" Or cmb_bulan.Text = "10" Or
cmb_bulan.Text = "12" Then
For i = 1 To 31
cmb_tgl.Items.Add(i)
Next i
cmb_tgl.Enabled = True
ElseIf cmb_bulan.Text = "4" Or cmb_bulan.Text = "6" Or cmb_bulan.Text = "9" Or
cmb_bulan.Text = "11" Then
For i = 1 To 30
cmb_tgl.Items.Add(i)
Next i
cmb_tgl.Enabled = True
End If
End If
End Sub
Private Sub btn_simpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
-3-

D:\Data Kuliah Semester 4 (4MTI1)\Pemrograman Visual\Latihan UTS VB.vb

07 April 2015 19:02

Handles btn_simpan.Click
Try
If txt_nama.Text = "" Or txt_nim.Text = "" Or txt_jurusan.Text = "" Or sem = 0 Or
cmb_tgl.Text = "" Or cmb_bulan.Text = "" Or cmb_tahun.Text = "" Then
MsgBox("Data tidak bisa disimpan, isi semua data dengan lengkap")
Else
btn_cetak.Enabled = True
data(indeks).nama = txt_nama.Text
data(indeks).nim = txt_nim.Text
data(indeks).jurusan = txt_jurusan.Text
data(indeks).semester = CStr(sem)
data(indeks).tanggal = cmb_tgl.Text
data(indeks).bulan = cmb_bulan.Text
data(indeks).tahun = cmb_tahun.Text
If indeks = UBound(data) Then
ReDim Preserve data(indeks + 1)
End If
indeks = indeks + 1
MsgBox("Data Berhasil Disimpan")
txt_nama.Clear()
txt_nim.Clear()
txt_jurusan.Clear()
rdb_1.Checked = False
rdb_2.Checked = False
rdb_3.Checked = False
rdb_4.Checked = False
rdb_5.Checked = False
rdb_6.Checked = False
rdb_7.Checked = False
rdb_8.Checked = False
sem = 0
cmb_tgl.Items.Clear()
cmb_tgl.Enabled = False
cmb_bulan.Items.Clear()
cmb_bulan.Enabled = False
End If
Catch ex As Exception
MsgBox("Data Gagal Disimpan")
End Try
End Sub
Private Sub btn_cetak_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btn_cetak.Click
lebar = 411
tinggi = 515
Me.Width = lebar
Me.Height = tinggi
btn_simpan.Enabled = False
btn_cetak.Enabled = False
btn_keluar.Enabled = False
txt_nama.Enabled = False
txt_nim.Enabled = False
txt_jurusan.Enabled = False
gpb_sem.Enabled = False
-4-

D:\Data Kuliah Semester 4 (4MTI1)\Pemrograman Visual\Latihan UTS VB.vb

07 April 2015 19:02

cmb_tgl.Enabled = False
cmb_bulan.Enabled = False
cmb_tahun.Enabled = False
lbl_cetak.Visible = True
cmb_data.Visible = True
cmb_data.Items.Clear()
For i = 1 To UBound(data) - 1
cmb_data.Items.Add(i)
Next
btn_ok.Visible = True
If cetak = 0 Then
btn_ok.Enabled = False
ElseIf cetak = 1 Then
btn_ok.Enabled = True
End If
btn_cancel.Visible = True
panel_hasil.Visible = False
End Sub
Private Sub btn_keluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btn_keluar.Click
End
End Sub
Private Sub cmb_data_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmb_data.SelectedIndexChanged
btn_ok.Enabled = True
End Sub
Private Sub btn_ok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
btn_ok.Click
cetak = 1
panel_hasil.Visible = True
lbl_text_nama.Text = data(CInt(cmb_data.Text)).nama
lbl_text_nim.Text = data(CInt(cmb_data.Text)).nim
lbl_text_jurusan.Text = data(CInt(cmb_data.Text)).jurusan
lbl_text_semester.Text = data(CInt(cmb_data.Text)).semester
lbl_text_tgl.Text = data(CInt(cmb_data.Text)).tanggal + "-" + data(CInt(cmb_data.Text)).
bulan + "-" + data(CInt(cmb_data.Text)).tahun
End Sub
Private Sub btn_cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btn_cancel.Click
lebar = 411
tinggi = 315
Me.Width = lebar
Me.Height = tinggi
lbl_cetak.Visible = False
cmb_data.Items.Clear()
cmb_data.Visible = False
btn_ok.Visible = False
btn_cancel.Visible = False
panel_hasil.Visible = False
btn_simpan.Enabled = True
-5-

D:\Data Kuliah Semester 4 (4MTI1)\Pemrograman Visual\Latihan UTS VB.vb

07 April 2015 19:02

btn_cetak.Enabled = True
btn_keluar.Enabled = True
txt_nama.Enabled = True
txt_nim.Enabled = True
txt_jurusan.Enabled = True
gpb_sem.Enabled = True
cmb_tahun.Enabled = True
End Sub
End Class

-6-