0% found this document useful (0 votes)
21 views7 pages

Modul 4 - Form Program Studi

The document describes how to create two new forms in Visual Basic - frmListProdi and frmEntryProdi. It provides the layout and properties for each form, including controls like buttons, text boxes, combo boxes and a datagridview. It also provides code to populate and manipulate the controls, connect to a database, insert/update/delete records, and handle events like clicking buttons or loading the forms. The code allows the user to view, add and edit records of program study data in a simple GUI application.

Uploaded by

Umar Adam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views7 pages

Modul 4 - Form Program Studi

The document describes how to create two new forms in Visual Basic - frmListProdi and frmEntryProdi. It provides the layout and properties for each form, including controls like buttons, text boxes, combo boxes and a datagridview. It also provides code to populate and manipulate the controls, connect to a database, insert/update/delete records, and handle events like clicking buttons or loading the forms. The code allows the user to view, add and edit records of program study data in a simple GUI application.

Uploaded by

Umar Adam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

14. Tambahkan Form baru dengan nama frmListProdi.

vb, Desain dengan layout


sbb :

Obyek Properties Nilai


FileName [Link]
Name frmListProdi
BackColor Pilih warna yg diinginkan
ForeColor Pilih warna yg diinginkan
Form
MaximizeBox False
MinimizeBox False
StartPosition CenterScreen
Text Daftar Data Program Studi
DataGridView Name DGV
Button1 Name btnTambah
Text Tambah
Name btnTutup
Button2
Text Tutup

Pemrograman Visual II by Amiruddin, [Link] 2021 45 | P a g e


 Lengkapi Codiong sbb :
Imports [Link]

Public Class frmListProdi

Sub Tampilkandata()
Dim btnEdit As New DataGridViewButtonColumn()
Dim btnHapus As New DataGridViewButtonColumn()
[Link]()
[Link]("kol0", "Kode Prodi")
[Link]("kol1", "Program Studi")
[Link]("kol2", "Jenjang")

Dim sql As String = "Select kode_prodi,nama_prodi,jenjang " & _


" from tbprogram_studi order by kode_prodi"
cmd = New OdbcCommand(sql, Conn)

rd = [Link]
Dim i As Integer = 0
While [Link]
[Link]()
[Link](0, i).Value = rd("kode_prodi")
[Link](1, i).Value = rd("nama_prodi")
[Link](2, i).Value = rd("jenjang")
i += 1
End While

[Link]()
[Link] = True
[Link] = False
[Link](0).Width = 80
[Link](1).Width = 200
[Link](2).Width = 80
[Link] = [Link]
[Link] = [Link]
[Link] = [Link]
[Link] = [Link]
[Link] = [Link]
[Link] = [Link]
[Link](0).[Link] = [Link]
[Link](2).[Link] = [Link]

[Link]().Add(btnEdit)
[Link] = ""
[Link] = "btEdit"
[Link] = "Edit"
[Link] = [Link]
[Link] = True
[Link]().Add(btnHapus)
[Link] = ""
[Link] = "btHapus"
[Link] = "Hapus"

Pemrograman Visual II by Amiruddin, [Link] 2021 46 | P a g e


[Link] = [Link]
[Link] = True
[Link](3).Width = 60
[Link](4).Width = 60

End Sub

Private Sub frmListProdi_Activated(ByVal sender As Object, ByVal e As [Link]) Handles [Link]


Tampilkandata()
End Sub

Private Sub frmListProdi_KeyPress(ByVal sender As Object, ByVal e As


[Link]) Handles [Link]
If Asc([Link]) = [Link] Then
[Link]("{tab}")
End If
End Sub

Private Sub frmListProdi_Load(ByVal sender As [Link], ByVal e As [Link]) Handles


[Link]
Call Tampilkandata()
End Sub

Private Sub DGV_CellContentClick(ByVal sender As [Link], ByVal e As


[Link]) Handles [Link]

If [Link] = 3 Then
tblEdit = True
frmProg_Studi.Text = "Edit Data Program Studi"
cKode_Prodi = [Link](0).Cells(0).Value()
frmProg_Studi.Show()
End If
If [Link] = 4 Then
cKode_Prodi = [Link](0).Cells(0).Value()
If [Link]("Yakin akan dihapus..?", "Hapus Data", [Link]) =
[Link] Then

cmd = New OdbcCommand("Delete from tbprogram_studi where kode_prodi='" & cKode_Prodi & "'",
Conn)
[Link]()

Tampilkandata()
End If
End If
End Sub

Private Sub btnTutup_Click(ByVal sender As [Link], ByVal e As [Link]) Handles


[Link]
[Link]()
End Sub

Pemrograman Visual II by Amiruddin, [Link] 2021 47 | P a g e


Private Sub btnTambah_Click(ByVal sender As [Link], ByVal e As [Link]) Handles
[Link]
tblEdit = False
frmProg_Studi.Text = "Tambah Data Program Studi"
frmProg_Studi.Show()
End Sub

End Class

[Link] Form Baru dengan nama [Link], Desain dengan


layout sbb :

Obyek Properties Nilai


FileName [Link]
Name frmEntryProdi
BackColor Pilih warna yg diinginkan
ForeColor Pilih warna yg diinginkan
Form
MaximizeBox False
MinimizeBox False
StartPosition CenterScreen
Text Entry Data Prodi
Label Text Isi sesuai dgn judulnya
TextBox1 Name txtKode
TextBox2 Name txtProdi
ComboBox1 Name cboJenjang
Name btnSimpan
Button1
Text Simpan
Name btnBatal
Button2
Text Batal

Pemrograman Visual II by Amiruddin, [Link] 2021 48 | P a g e


 Lengkapi Codiong sbb :

Imports [Link]
Public Class frmEntryProdi

Sub TampilJenjang()
[Link]()
cmd = New OdbcCommand("select distinct jenjang from tbprogram_studi order by kode_prodi", Conn)
rd = [Link]
While [Link]
[Link]([Link](0))
End While
End Sub

Sub kosongkan()
[Link] = ""
[Link] = ""
[Link] = ""
[Link] = True
[Link]()
End Sub

Sub CekData()
cmd = New OdbcCommand("select * from tbprogram_studi where kod_prodi='" & [Link] & "' ", Conn)
rd = [Link]
[Link]()
If [Link] = True Then
[Link] = [Link]("kod_prodi")
[Link] = [Link]("nama_prodi")
[Link] = [Link]("jenjang")
cId_Periode = [Link]("kode_fak")
[Link] = False
Else
[Link] = ""
[Link] = ""

End If
End Sub

Sub Validasi()
If [Link] = "" Then
MsgBox("Nama Prodi Belum diisi", , "Perhatian...!")
[Link]()
Valid = False
Exit Sub
Else
Valid = True
End If

If [Link] = "" Then


MsgBox("Jenjang Program Studi Belum diisi", , "Perhatian...!")

Pemrograman Visual II by Amiruddin, [Link] 2021 49 | P a g e


[Link]()
valid = False
Exit Sub
Else
valid = True
End If
End Sub

Private Sub btnSimpan_Click(ByVal sender As [Link], ByVal e As [Link]) Handles


[Link]
Call Validasi()

If valid = True Then


cmd = New OdbcCommand("Select * from tbprogram_studi where kode_prodi='" & [Link] & "' ",
Conn)
rd = [Link]
[Link]()
If Not [Link] Then
Dim sqltambah As String = "Insert into tbprogram_studi (kode_prodi,nama_prodi,jenjang) values " & _
"('" & [Link] & "','" & [Link] & "', " & _
"'" & [Link] & "')"
cmd = New OdbcCommand(sqltambah, Conn)

Else
Dim sqledit As String = "Update tbprogram_studi set " & _
"nama_prodi='" & [Link] & "', " & _
"jenjang='" & [Link] & "' " & _
" where kode_prodi='" & [Link] & "' "
cmd = New OdbcCommand(sqledit, Conn)

End If
[Link]()
[Link]()
[Link] = False
[Link]()
End If
End Sub

Private Sub btnBatal_Click(ByVal sender As [Link], ByVal e As [Link]) Handles [Link]


[Link]()
[Link] = False
[Link]()
End Sub

Private Sub frmEntryProdi_KeyPress(ByVal sender As Object, ByVal e As


[Link]) Handles [Link]
If Asc([Link]) = [Link] Then
[Link]("{tab}")
End If
End Sub

Pemrograman Visual II by Amiruddin, [Link] 2021 50 | P a g e


Private Sub frmEntryProdi_Load(ByVal sender As [Link], ByVal e As [Link]) Handles
[Link]
Call TampilJenjang()
If tblEdit = False Then
Call kosongkan()
Else
[Link] = False

cmd = New OdbcCommand("select * from tbprogram_studi where kode_prodi='" & cKode_Prodi & "' ",
Conn)
rd = [Link]
[Link]()
If [Link] = True Then
[Link] = [Link]("kode_prodi")
[Link] = [Link]("nama_prodi")
[Link] = [Link]("jenjang")

End If
End If
End Sub

End Class

Pemrograman Visual II by Amiruddin, [Link] 2021 51 | P a g e

You might also like