Kali ini saya ingin berbagi sedikit tentang bahasa pemrograman VB.Net. Saya akan membagikan aplikasi Alkitab Elektronik sederhana beserta dengan source code nya.
Pertama-tama kita membutuhkan database Alkitab. Bisa di unduh dari link berikut.
Buatlah form sesuai dengan bentuk di bawah ini dengan nama kontrol sebagai berikut.
- MenuStrip1 As System.Windows.Forms.MenuStrip
- TSCB_PERJANJIAN As System.Windows.Forms.ToolStripComboBox
- TableLayoutPanel1 As System.Windows.Forms.TableLayoutPanel
- Pasal_lb As System.Windows.Forms.ListBox
- Buku_lb As System.Windows.Forms.ListBox
- Ayat_rtb As System.Windows.Forms.RichTextBox
- InfoToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
Masukkan "Perjanjian Lama" dan "Perjanjian Baru" pada item Combobox.
Buatlah sebuah class untuk koneksi ke database kemudian masukkan kode di bawah ini.
Imports Microsoft.VisualBasic
Imports System
Imports System.Data
Imports System.Data.OleDb
Public Class AccessDBCon
' Methods
Public Sub CloseConn()
If Not IsNothing(Cn) Then
Cn.Close()
Cn = Nothing
End If
End Sub
Public Sub ExecuteNonQuery(ByVal Query As String)
If Not OpenConn() Then
MsgBox("Koneksi Gagal..!!", MsgBoxStyle.Critical, "Access Failed..!!")
Exit Sub
End If
Cmd = New OleDb.OleDbCommand
Cmd.Connection = Cn
Cmd.CommandType = CommandType.Text
Cmd.CommandText = Query
Cmd.ExecuteNonQuery()
Cmd = Nothing
CloseConn()
End Sub
Public Function ExecuteQuery(ByVal Query As String) As DataTable
If Not OpenConn() Then
MsgBox("Koneksi Gagal..!!", MsgBoxStyle.Critical, "Access Failed")
Return Nothing
Exit Function
End If
Cmd = New OleDb.OleDbCommand(Query, Cn)
Da = New OleDb.OleDbDataAdapter
Da.SelectCommand = Cmd
Ds = New Data.DataSet
Da.Fill(Ds)
Dt = Ds.Tables(0)
Return Dt
Dt = Nothing
Ds = Nothing
Da = Nothing
Cmd = Nothing
CloseConn()
End Function
Public Function OpenConn() As Boolean
Cn = New OleDb.OleDbConnection("Provider=" & provider & ";Data Source=ESHB-AE01-Alkitab Terjemahan Baru.mdb;Persist Security Info=False;JET OLEDB:Database Password=")
Cn.Open()
If Cn.State <> ConnectionState.Open Then
Return False
Else
Return True
End If
End Function
' Fields
Protected Cmd As OleDbCommand
Protected Cn As OleDbConnection
Protected Da As OleDbDataAdapter
Protected Ds As DataSet
Protected Dt As DataTable
Protected provider As String = "Microsoft.ACE.OLEDB.12.0"
Protected SQL As String
End Class
Buatlah sebuah modul untuk mendeklarasikan class yang dibuat tadi agar dapat digunakan secara Public. Masukkan kode di bawah ini dalam modul tersebut
Module GeneralModul
Public PROSES As New AccessDBCon
End Module
Setelah itu, masukkan koding di bawah ini dibalik form utama.
Public TBLBUKU As New DataTable
Public TBLPASAL As New DataTable
Public TBLAYAT As New DataTable
Public Perjanjian As String
Public IB As Integer
Public IP As Integer
Sub TAMPILKAN_BUKU()
Dim DARI As Integer
Dim SAMPAI As Integer
If TSCB_PERJANJIAN.Text = "Perjanjian Lama" Then
DARI = 1
SAMPAI = 39
ElseIf TSCB_PERJANJIAN.Text = "Perjanjian Baru" Then
DARI = 40
SAMPAI = 66
End If
TBLBUKU = PROSES.ExecuteQuery("SELECT BIBLE.BIBLETEXT FROM BIBLE WHERE (((BIBLE.BOOK)=0) AND ((BIBLE.CHAPTER)=10) AND ((BIBLE.VERSE)>=" & DARI & " And (BIBLE.VERSE)<=" & SAMPAI & "));")
Buku_lb.Items.Clear()
For A As Integer = 0 To TBLBUKU.Rows.Count - 1
Buku_lb.Items.Add(TBLBUKU.Rows(A).Item(0).ToString)
Next
End Sub
Private Sub TSCB_PERJANJIAN_SelectedIndexChanged(sender As Object, e As EventArgs) Handles TSCB_PERJANJIAN.SelectedIndexChanged
Perjanjian = sender.text
TAMPILKAN_BUKU()
Buku_lb.SelectedIndex = 0
End Sub
Sub TAMPILKAN_PASAL(INDEKS_BUKU As Integer)
TBLPASAL = PROSES.ExecuteQuery("SELECT BIBLE.CHAPTER FROM BIBLE GROUP BY BIBLE.BOOK, BIBLE.CHAPTER HAVING (((BIBLE.BOOK)=" & INDEKS_BUKU & "));")
Pasal_lb.Items.Clear()
For A As Integer = 0 To TBLPASAL.Rows.Count - 1
Pasal_lb.Items.Add(TBLPASAL.Rows(A).Item(0).ToString)
Next
End Sub
Private Sub Buku_lb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles Buku_lb.SelectedIndexChanged
IB = sender.SELECTEDINDEX + 1
If TSCB_PERJANJIAN.Text = "Perjanjian Lama" Then
IB = sender.SELECTEDINDEX + 1
ElseIf TSCB_PERJANJIAN.Text = "Perjanjian Baru" Then
IB = sender.SELECTEDINDEX + 40
End If
TAMPILKAN_PASAL(IB)
Pasal_lb.SelectedIndex = 0
End Sub
Private Sub Pasal_lb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles Pasal_lb.SelectedIndexChanged
IP = sender.SELECTEDINDEX + 1
TAMPILKAN_AYAT(IB, IP)
End Sub
Sub TAMPILKAN_AYAT(INDEKS_BUKU As Integer, INDEKS_PASAL As Integer)
TBLAYAT = PROSES.ExecuteQuery("SELECT BIBLE.BIBLETEXT, BIBLE.VERSE, BIBLE.CHAPTER, BIBLE.BOOK FROM BIBLE WHERE (((BIBLE.CHAPTER)=" & INDEKS_PASAL & ") AND ((BIBLE.BOOK)=" & INDEKS_BUKU & "));")
Ayat_rtb.Clear()
Dim ayat_full As String = ""
For A As Integer = 0 To TBLAYAT.Rows.Count - 1
If ayat_full = "" Then
ayat_full = Pasal_lb.Text & ":" & (A + 1) & " " & (TBLAYAT.Rows(A).Item(0).ToString)
Else
ayat_full = ayat_full & Environment.NewLine & Pasal_lb.Text & ":" & (A + 1) & " " & (TBLAYAT.Rows(A).Item(0).ToString)
End If
Next
Ayat_rtb.Text = ayat_full
'For A As Integer = 0 To TBLAYAT.Rows.Count - 1
' If Ayat_rtb.Text = "" Then
' Ayat_rtb.Text = Pasal_lb.Text & ":" & (A + 1) & " " & (TBLAYAT.Rows(A).Item(0).ToString)
' Else
' Ayat_rtb.Text = Ayat_rtb.Text & Environment.NewLine & Pasal_lb.Text & ":" & (A + 1) & " " & (TBLAYAT.Rows(A).Item(0).ToString)
' End If
'Next
End Sub
Setelah itu silahkan di jalankan aplikasi ini.
Untuk melihat aplikasi dalam bentuk exe, silahkan ke link ini.
Bagi Anda yang ingin mendapatkan source code, silahkan menghubungi Admin.
Sekian postingan kali ini, semoga bermanfaat.