Pada postingan kali ini saya akan membahas tentang pembuatan form login dan form menghitung nilai siswa dalam angka dan dalam bentuk huruf.Untuk membuat program ini dibutuhkan database sebagai tempat penyimpanan datanya.Dan database yang digunakan yaitu Microsoft Access ...
PENJELASAN PROGRAM YANG AKAN DIBUAT
Kali ini kita akan membuat program untuk menghitung nilai rata-rata seorang siswa yang dihitung dari nilai tugas(20%),nilai UTS(30%) dan nilai UAS(50%).Jadi pertama-tama kita akan membuat form untuk menyimpan data siswa(nim dan nama siswa) kemudian jika kita membuka form nilai siswa,kita dapat secara otomatis mencari siswa yang kita inginkan untuk dihitung nilainya dengan mengklik combo box yang sudah menyimpan data siswa di form data siswa.
MEMBUAT DATABASE
2.Kemudian simpan nama database dengan nilaisiswa.mdb
3.Setelah itu klik create pada tab microsoft access dan pilih table (CREATE→TABLE).Dan buatlah 2 tabel (tabel data siswa dan tabel nilai siswa)
3.Setelah itu klik create pada tab microsoft access dan pilih table (CREATE→TABLE).Dan buatlah 2 tabel (tabel data siswa dan tabel nilai siswa)
4.Setelah itu buatlah isi tabel data siswa (Caranya klik kanan pada tabel data siswa dan pilih design view)
Pada Field Name tuliskan :
NIM dengan tipe datanya short text (field size 50)
NamaSiswa tipe datanya short text (field size 50)
Kemudian simpan tabel dengan nama tbdatasiswa.
NIM dengan tipe datanya short text (field size 50)
NamaSiswa tipe datanya short text (field size 50)
Kemudian simpan tabel dengan nama tbdatasiswa.
berikut adalah capturan picture :
sourcode :
Imports System.Data
Imports System.Data.OleDb
Imports Word = Microsoft.Office.Interop.Word
Imports Excel = Microsoft.Office.Interop.Excel
Public Class _Default
Inherits System.Web.UI.Page
Dim koneksi As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Data Sinau\Pemrograman II\nilai_mahasiswa.accdb"
Dim objekkoneksi As New OleDb.OleDbConnection(koneksi)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim G As Double
Dim S As Double
G = Val(TextBox3.Text) + Val(TextBox4.Text) + Val(TextBox5.Text)
S = G / 3
If S >= 80 Then
TextBox6.Text = "A"
ElseIf S < 80 And S >= 70 Then
TextBox6.Text = "B"
ElseIf S < 70 And S >= 60 Then
TextBox6.Text = "C"
ElseIf S < 60 Then
TextBox6.Text = "D"
End If
End Sub
Protected Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
Dim response As MsgBoxResult
response = MsgBox("Apakah data akan dihapus?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Confirm")
If response = MsgBoxResult.Yes Then
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
ElseIf response = MsgBoxResult.No Then
End If
End Sub
Protected Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
End Sub
Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim AppExcelnya As New Excel.Application
Dim ExcelWB As Excel.Workbook
ExcelWB = AppExcelnya.Workbooks.Open("D:\Data Sinau\Pemrograman II\Nilai_mahasiswa.xlsx")
AppExcelnya.Range("A2" + 1).Value = TextBox1.Text
AppExcelnya.Range("B2" + 1).Value = TextBox2.Text
AppExcelnya.Range("C2" + 1).Value = TextBox3.Text
AppExcelnya.Range("D2" + 1).Value = TextBox4.Text
AppExcelnya.Range("E2" + 1).Value = TextBox5.Text
AppExcelnya.Range("F2" + 1).Value = TextBox6.Text
If TextBox1.Text = "" or TextBox2.Text = "" or TextBox3.Text = "" or TextBox4.Text = "" or TextBox5.Text = "" or TextBox6.Text = "" or Then
MsgBox(" Data harus diisi semua ")
Else
ExcelWB.Save()
AppExcelnya.Visible = True
MsgBox("Data berhasil disimpan")
End If
End Sub
Protected Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim Appnya As New Word.Application
Dim Dokumennya As Word.Document
Dokumennya = Appnya.Documents.Open("D:\Data Sinau\Pemrograman II\Nilai_mahasiswa.docx")
Dokumennya.Bookmarks("nim").Select()
Appnya.Selection.TypeText(TextBox1.Text)
Dokumennya.Bookmarks("nama").Select()
Appnya.Selection.TypeText(TextBox2.Text)
Dokumennya.Bookmarks("ntugas").Select()
Appnya.Selection.TypeText(TextBox3.Text)
Dokumennya.Bookmarks("nuts").Select()
Appnya.Selection.TypeText(TextBox4.Text)
Dokumennya.Bookmarks("nuas").Select()
Appnya.Selection.TypeText(TextBox5.Text)
Dokumennya.Bookmarks("gride").Select()
Appnya.Selection.TypeText(TextBox6.Text)
If TextBox1.Text = "" or TextBox2.Text = "" or TextBox3.Text = "" or TextBox4.Text = "" or TextBox5.Text = "" or TextBox6.Text = "" or Then
MsgBox(" Data harus diisi semua ")
Else
Dokumennya.SaveAs("D:\Data Sinau\Pemrograman II\Nilai_mahasiswa.docx" + TextBox1.Text)
Appnya.Visible = True
MsgBox("Data berhasil disimpan")
End If
End Sub
Protected Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
objekkoneksi.Close()
objekkoneksi.Open()
Dim tambah As String = "INSERT INTO datanilai values ('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "') "
Dim oCmd = New OleDbCommand(tambah, objekkoneksi)
oCmd.ExecuteNonQuery()
objekkoneksi.Close()
MsgBox("Data berhasil disimpan")
End Sub
End Class