Cara Membuat Progam/Apliaksi Latihan 12
Dengan
Software Microsoft Visual Basic 2008
Langkah 1:
Buka
Aplikasi Visual Basic 2008/Visual Studio 2008
Langkah 2 :
Buat Project Baru dengan Cara,
- File| New Project | Windows From
Application,
- Dan Nama Project Tersebut.
-
Lihat Gambar Berikut :
Langkah Ke 3 :
Rancanglah From
Seperti Gambar Berikut Berikut :
Komponen Dan Properti Untuk Form
Sebagai Berikut :
Komponen
|
Properties
|
Form
|
Text
: Latihan_12_36110054
|
Groupbox
|
Text
: Formulir
|
Label
|
Text
: No. Pembelian
|
Label
|
Text
: Nama Barang
|
Label
|
Text
: Harga Perunit
|
Label
|
Text
: Tanggal
|
Label
|
Text
: Unit
|
Label
|
Text
: Jumlah
|
Button
|
Text
: Simpan
|
Textbox
|
-
|
Textbox
|
-
|
Textbox
|
-
|
Datetimepicker
|
-
|
Textbox
|
-
|
Textbox
|
-(status
: Readonly True)
|
Groupbox
|
Text:
Data
|
Datagridview
|
-
|
Label
|
Text:
Total Unit (status : Readonly True)
|
Label
|
Text:
Total (status : Readonly True)
|
Groupbox
|
Text:
Berdasarkan No. Baris
|
Label
|
Text:
No. Baris
|
Button
|
Text:
Tampilkan
|
Button
|
Text:
Hapus
|
Textbox
|
-
|
Groupbox
|
Text:
Berdasarkan No. Pembelian
|
Label
|
Text:
No. Pembelian
|
Button
|
Text:
Tampilkan
|
Button
|
Text:
Hapus
|
Textbox
|
-
|
Groupbox
|
Text:
Berdasarkan Baris Sekarang
|
Label
|
Text:
Baris Sekarang
|
Button
|
Text:
Tampilkan
|
Langkah 4 :
Masukkan
Rumus untuk menjalankan form di atas .
Berikut
ini Rumus untuk menjalankan form :
Public NotInheritable Class Latihan_12_36110054
Dim table As New DataTable
Private Sub Latihan_12_36110054_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
table.Columns.Add(New DataColumn("No. Pembelian", GetType(String)))
table.Columns.Add(New DataColumn("Nama Barang", GetType(String)))
table.Columns.Add(New DataColumn("Harga Perunit", GetType(Double)))
table.Columns.Add(New DataColumn("Tanggal Pembelian", GetType(Date)))
table.Columns.Add(New DataColumn("Unit", GetType(Integer)))
table.Columns.Add(New DataColumn("Jumlah", GetType(Double)))
DataGridView_36110054.DataSource = table
Dim Kolom(1) As DataColumn
Kolom(0) = table.Columns("No. Pembelian")
table.PrimaryKey = Kolom
End Sub
Private Sub Harga_36110054_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Harga_36110054.TextChanged, Unit_36110054.TextChanged
Jumlah_36110054.Text = Val(Harga_36110054.Text) * Val(Unit_36110054.Text)
End Sub
Private Sub Simpan_36110054_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Simpan_36110054.Click
Dim baris As DataRow
baris = table.Rows.Find(NPB_36110054.Text)
If baris Is Nothing Then
baris = table.NewRow
baris("No. Pembelian") = NPB_36110054.Text
baris("Nama Barang") = Barang_36110054.Text
baris("Harga Perunit") = Val(Harga_36110054.Text)
baris("Tanggal Pembelian") = DateTimePicker1.Value.Date
baris("Unit") = Val(Unit_36110054.Text)
baris("Jumlah") = Val(Jumlah_36110054.Text)
table.Rows.Add(baris)
NPB_36110054.Text = ""
Barang_36110054.Text = ""
Harga_36110054.Text = ""
Unit_36110054.Text = ""
Jumlah_36110054.Text = ""
Else
MsgBox("Baris Sudah Ada")
Jumlah_36110054.Text = ""
End If
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim baris As DataRow
If Val(NoBaris_36110054.Text) <= table.Rows.Count Then
baris = table.Rows(Val(NoBaris_36110054.Text) - 1)
NPB_36110054.Text = baris("no. pembelian")
Barang_36110054.Text = baris("nama barang")
Harga_36110054.Text = baris("harga perunit")
DateTimePicker1.Value = baris("tanggal pembelian")
Unit_36110054.Text = baris("unit")
Jumlah_36110054.Text = baris("jumlah")
Else
MsgBox("baris terlalu besar")
End If
NoBaris_36110054.Text = ""
End Sub
Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim baris As DataRow
If Val(NoBaris_36110054.Text) <= table.Rows.Count Then
baris = table.Rows(Val(NoBaris_36110054.Text) - 1)
baris.Delete()
Else
MsgBox("no. baris yang dimasukkan tidak ada")
End If
NoBaris_36110054.Text = ""
End Sub
Private Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim baris As DataRow
baris = table.Rows.Find(NoPembelian_36110054.Text)
If Not baris Is Nothing Then
NPB_36110054.Text = baris("no. pembelian")
Barang_36110054.Text = baris("nama barang")
Harga_36110054.Text = baris("harga perunit")
DateTimePicker1.Value = baris("tanggal pembelian")
Unit_36110054.Text = baris("unit")
Jumlah_36110054.Text = baris("jumlah")
Else
MsgBox("no. pembelian tidak ada")
End If
NoPembelian_36110054.Text = ""
End Sub
Private Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim baris As DataRow
baris = table.Rows.Find(NoPembelian_36110054.Text)
If Not baris Is Nothing Then
baris.Delete()
NoPembelian_36110054.Text = ""
Else
MsgBox("no. pembelian yang dimasukkan tidak ada")
NoPembelian_36110054.Text = ""
End If
End Sub
Private Sub Button5_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim baris As DataRow
baris = table.DefaultView(BindingContext(table).Position).Row
NPB_36110054.Text = baris("no. pembelian")
Barang_36110054.Text = baris("nama barang")
Harga_36110054.Text = baris("harga perunit")
DateTimePicker1.Value = baris("tanggal pembelian")
Unit_36110054.Text = baris("unit")
Jumlah_36110054.Text = baris("jumlah")
End Sub
Private Sub Button6_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button6.Click
Dim baris As DataRow
baris = table.DefaultView(BindingContext(table).Position).Row
baris.Delete()
End Sub
Private Sub DataGridView_36110054_DataBindingComplete(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewBindingCompleteEventArgs) Handles DataGridView_36110054.DataBindingComplete
Dim tu, total As Integer
For Each x As DataRow In table.Rows
tu = tu + x("unit")
total = total + x("jumlah")
Next
Total_unit_36110054.Text = tu
Total_36110054.Text = total
End Sub
End Class




Tidak ada komentar:
Posting Komentar