Public Class Form1
Private Sub BtnAdd_Click(sender As Object, e As EventArgs) Handles BtnAdd.Click
If BtnAdd.Text = "Add" Then
namabrg.Text = ""
kodebrg.Text = ""
kuantitas.Text = ""
harga.Text = ""
totharga.Text = ""
namabrg.Focus()
BtnAdd.Text = "Save"
Else
Objek.Open()
Dim Add As String = "INSERT INTO TabelSupermarket values ('" & namabrg.Text & "', '" & kodebrg.Text & "', '" & kuantitas.Text & "', '" & harga.Text.Text & "', '" & totharga.Text & "')"
Dim oCMD = New OleDbCommand(Add, Objek)
oCMD.ExecuteNonQuery()
Objek.Close()
MsgBox("Sukses")
BtnAdd.Text = "Add"
End If
End Sub
End Sub
Private Sub BtnFind_Click(sender As Object, e As EventArgs) Handles BtnFind.Click
Dim Kode As String = InputBox("Masukkan Nama")
If Not Len(Kode) = 0 Then
Objek.Close()
Objek.Open()
Dim Cari As String = "SELECT * FROM DaftarWP where nama = '" + Kode + "'"
Dim oCMD = New OleDbCommand(Cari, Objek)
xReader = oCMD.ExecuteReader
If xReader.HasRows Then
xReader.Read()
namabrg.Text = xReader("tipe")
kodebrg.Text = xReader("nama")
kuantitas.Text = xReader("ukuran")
harga.Text = xReader("umur")
totharga.Text = xReader("harga")
Else
MsgBox("namaWP" + Kode + "tidak ada")
namabrg.Text = ""
kodebrg.Text = ""
kuantitas.Text = ""
harga.Text.Text = ""
totharga.Text = ""
namabrg.Focus()
End If
End If
End Sub
End Sub
Private Sub btnEdit_Click(sender As Object, e As EventArgs) Handles btnEdit.Click
Objek.Close()
Objek.Open()
Dim Ubah As String = "UPDATE DaftarWP set tipe = '" & namabrg.Text & "', ukuran = '" & kodebrg.Text & "', umur = '" & kuantitas.Text & "', harga = '" & txtharga.Text & "' where nama = '" & txtnama.Text & "'"
Dim oCMD = New OleDbCommand(Ubah, Objek)
oCMD.ExecuteNonQuery()
Objek.Close()
MsgBox("Sukses")
End Sub
End Sub
Private Sub btnView_Click(sender As Object, e As EventArgs) Handles btnView.Click
Form2.Show()
End Sub
End Sub
Private Sub BtnPrint_Click(sender As Object, e As EventArgs) Handles BtnPrint.Click
Form3.Show()
End Sub
End Sub
Private Sub BtnClose_Click(sender As Object, e As EventArgs) Handles BtnClose.Click
Me.Close()
End Sub
End Sub
Private Sub BtnDelete_Click(sender As Object, e As EventArgs) Handles BtnDelete.Click
Objek.Close()
Objek.Open()
Dim Hapus As String = "DELETE FROM TabelSupermarket where tipe = '" & txttipe.Text & "'"
Dim oCMD = New OleDbCommand(Hapus, Objek)
oCMD.ExecuteNonQuery()
namabrg.Text = ""
kodebrg.Text = ""
kuantitas.Text = ""
harga.Text.Text = ""
totharga.Text = ""
namabrg.Focus()
MsgBox("Data berhasil dihapus")
End Sub
End Sub
End Class
Kamis, 15 Desember 2016
Minggu, 16 Oktober 2016
Automation ( VB.net terhubung oleh Ms. Excel dan Ms.Word, )
Selamat Malam semua!
Kali ini saya akan share bagaimana cara membuat VB.Net yang terhubung oleh Ms. Excel dan Ms.Word, kali ini form yang saya buat adalah Table nilai untuk ms. excel dan Form Nilai Mahasiswa untuk ms.word.
Dalam Form VB sendiri nanti nya harus tereferensi oleh Ms. excel&word itu sendiri, agar dapat saling terhubung. berikut adalah bagaimana saya membuat Progam ini
Public Class Form1
Dim AppWord As New
Microsoft.Office.Interop.Word.Application
Dim DocWord As
Microsoft.Office.Interop.Word.Document
Dim excelApp As New
Microsoft.Office.Interop.Excel.Application
Dim MyExcelBook As
Microsoft.Office.Interop.Excel.Workbook
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
DocWord = AppWord.Documents.Open("C:\Users\Farah\Documents\farahpembis.docx")
DocWord.Bookmarks("Nama").Select()
AppWord.Selection.TypeText(TextBox1.Text)
DocWord.Bookmarks("npm").Select()
AppWord.Selection.TypeText(TextBox2.Text)
DocWord.Bookmarks("ujian1").Select()
AppWord.Selection.TypeText(TextBox3.Text)
DocWord.Bookmarks("ujian2").Select()
AppWord.Selection.TypeText(TextBox4.Text)
DocWord.Bookmarks("ujian3").Select()
AppWord.Selection.TypeText(TextBox5.Text)
DocWord.Bookmarks("keterangan").Select()
AppWord.Selection.TypeText(TextBox6.Text)
AppWord.Selection.Font.Name = "Arial"
'menghitung nilai
akhir
Dim hasil As New Integer
hasil = ((Convert.ToInt32(TextBox3.Text)) +
(Convert.ToInt32(TextBox4.Text)) + (Convert.ToInt32(TextBox5.Text))) / 3
'memunculkan tulisan
lulus/tidak lulus pada textbox keterangan
If hasil >= 65 Then
TextBox6.Text = "Lulus"
Else
TextBox6.Text = "Tidak Lulus"
End If
DocWord.SaveAs2("C:\Users\Farah\Documents\utsfrh1")
AppWord.Visible = True
AppWord.Quit()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
MyExcelBook = excelApp.Workbooks.Open("C:\Users\Farah\Documents\frhuts2.xlsx")
excelApp.Range("C4").Value
= TextBox3.Text
excelApp.Range("C5").Value
= TextBox4.Text()
excelApp.Range("C6").Value
= TextBox5.Text
excelApp.Range("C8").Value
= TextBox6.Text
MyExcelBook.SaveAs("C:\Users\Farah\Documents\frhuts4.xlsx")
'menghitung nilai
akhir
Dim hasil As New Integer
hasil = ((Convert.ToInt32(TextBox3.Text)) +
(Convert.ToInt32(TextBox4.Text)) + (Convert.ToInt32(TextBox5.Text))) / 3
'memunculkan tulisan
lulus/tidak lulus pada textbox keterangan
If hasil >= 65 Then
TextBox6.Text = "Lulus"
Else
TextBox6.Text = "Tidak Lulus"
End If
excelApp.Visible = True
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
TextBox1.Text = " "
TextBox2.Text = " "
TextBox3.Text = " "
TextBox4.Text = " "
TextBox5.Text = " "
TextBox6.Text = " "
TextBox1.Focus()
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
End
End Sub
End Class
Langganan:
Postingan (Atom)