Membuat tampilan menu pada vb.net
• Klik kanan projek->Add->New Item-> pilih “MDI Parent Form”
• Maka tampil seperti ini
• Kemudian ubah nama menu tersebut sesuai nama yang akan ditampilkan.
• Kemudian klik 2x, untuk mengganti sintaxnya
Private Sub ShowNewForm(ByVal sender As Object, ByVal e As EventArgs) Handles NewToolStripMenuItem.Click, NewToolStripButton.Click, NewWindowToolStripMenuItem.Click
Form1.Show()
End Sub
• Kemudian running Mdi Parent Form tersebut
• Jika sudah tampil seperti diatas maka form MDI Parent Form telah selesai
• Selamat mencoba……
Kamis, 09 Juni 2011
MEMBUAT MODULE UNTUK KONEKSI
Berikut ini merupakan cara sederhana untuk membuat koneksi database dari VB 2008 ke database source SQL 2000. Coding koneksi ini dibuat dalam sebuah modul dimana bertujuan agar modul koneksi dapat dipanggil selama form yang menggunakan koneksi masih berada dalam 1 Project.
Buatlah sebuah project baru
File >> New Project >> Pilih Windows Form>>Lalu beri nama project tersebut
Kemudian
Klik kanan pada project >>add>> Module>> beri nama module anda
Kemudian ketikkan source kode berikut :
Imports System.Data
Imports System.Data.Sql
Module konek
Public database As New OleDb.OleDbConnection
Public tampil2 As New OleDb.OleDbCommand
Public tampilkan As OleDb.OleDbDataReader
Public hasilcek As String
Public Sub bukakoneksi()
database.Close()
Try
database.ConnectionString = "provider=sqloledb.1;integrated security=SSPI;persist security info=false; initial catalog=cobasql;data source=."
database.Open()
MessageBox.Show("Koneksi kedatabase berhasil")
Catch ex As Exception
MessageBox.Show("koneksi gagal")
End
End Try
End Sub
End Module
Masukkan nama database yang ingin kita koneksikan pada bagian ini :
initial catalog=cobasql
Untuk mencoba mengetes running module tersebut, buatlah sebuah form dengan 1 button seperti berikut :
Lalu pada codding, panggil module koneksi tadi,
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call bukakoneksi()
End Sub
End Class
Kemudian jalankan,
Buatlah sebuah project baru
File >> New Project >> Pilih Windows Form>>Lalu beri nama project tersebut
Kemudian
Klik kanan pada project >>add>> Module>> beri nama module anda
Kemudian ketikkan source kode berikut :
Imports System.Data
Imports System.Data.Sql
Module konek
Public database As New OleDb.OleDbConnection
Public tampil2 As New OleDb.OleDbCommand
Public tampilkan As OleDb.OleDbDataReader
Public hasilcek As String
Public Sub bukakoneksi()
database.Close()
Try
database.ConnectionString = "provider=sqloledb.1;integrated security=SSPI;persist security info=false; initial catalog=cobasql;data source=."
database.Open()
MessageBox.Show("Koneksi kedatabase berhasil")
Catch ex As Exception
MessageBox.Show("koneksi gagal")
End
End Try
End Sub
End Module
Masukkan nama database yang ingin kita koneksikan pada bagian ini :
initial catalog=cobasql
Untuk mencoba mengetes running module tersebut, buatlah sebuah form dengan 1 button seperti berikut :
Lalu pada codding, panggil module koneksi tadi,
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call bukakoneksi()
End Sub
End Class
Kemudian jalankan,
MENGUPDATE DATA
Bahasan kali ini qt akan membuat input data, dan langsung tersimpan dalam data base dan menampilkan hasil yang telah qt input. Nemun sebelumnya, buatlah dulu sebuah database dlm sql 2000 sesuai yg dibutuhkan, pada contoh ini database yg digunakan sama dengan bahasan sebelumnya, dengan tambahan table Jurusan>>berisi colum >>kdjur(kode jurusan) dan >>nmjur(nama jurusan)
Buat form berikut:
Kemudian ketikkan coding berikut:
Public Class update
Sub kosong()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox1.Focus()
End Sub
Sub netral()
Button1.Text = "Tambah"
Button2.Text = "Ubah"
Button3.Text = "Hapus"
Button4.Text = "Keluar"
Button1.Enabled = True 'enable=funsi aktif/tdaknya sebuah objek
Button2.Enabled = True
Button3.Enabled = True
Button4.Enabled = True
End Sub
Sub celrecord()
Call bukakoneksi()
tampil2.Connection = database
tampil2.CommandType = CommandType.Text
tampil2.CommandText = "select * from jurusan where kdjur='" & Trim(TextBox1.Text) & "'"
tampilkan = tampil2.ExecuteReader
If tampilkan.HasRows = True Then ''ada atau tidak recod yg dimaksukkan
hasilcek = True
Else
hasilcek = False
End If
End Sub
Sub simpankelompok()
If Button1.Text = "Tambah" Then
TextBox1.Text = ""
Button1.Text = "Simpan"
Button2.Enabled = False
Button3.Enabled = False
Button4.Text = "Batal"
TextBox1.Focus()
Else
If TextBox1.Text = "" Then Exit Sub
If TextBox2.Text = "" Then Exit Sub
End If
Call celrecord()
Try
If hasilcek = False Then
Call bukakoneksi()
tampil2.Connection = database
tampil2.CommandType = CommandType.Text
tampil2.CommandText = "Insert into jurusan (kdjur,nmjur)values('" & TextBox1.Text & "','" & TextBox2.Text & "')"
tampil2.ExecuteNonQuery()
Call kosong()
Else
MsgBox("data sudah ada, silahkan cek data yang diinput", MsgBoxStyle.Critical, "input data") 'critical =! dalam msgbox
End If
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub
Sub ubahkelompok()
If Button2.Text = "Ubah" Then
TextBox1.Text = ""
Button2.Text = "Simpan"
Button1.Enabled = False
Button3.Enabled = False
Button4.Text = "Batal"
TextBox1.Focus()
Else
If TextBox1.Text = "" Then Exit Sub
If TextBox2.Text = "" Then Exit Sub
End If
Try
Call bukakoneksi()
tampil2.Connection = database
tampil2.CommandType = CommandType.Text
tampil2.CommandText = "Update Jurusan set nmjur='" & Trim(TextBox2.Text) & "'where kdjur='" & TextBox1.Text & "'"
tampil2.ExecuteNonQuery()
Call kosong()
TextBox1.Focus()
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub
Sub hapuskelompok()
If Button3.Text = "Hapus" Then
TextBox1.Text = ""
Button3.Text = "OK"
Button1.Enabled = False
Button2.Enabled = False
Button4.Text = "Batal"
TextBox1.Focus()
Else
If TextBox1.Text = "" Then Exit Sub
If TextBox2.Text = "" Then Exit Sub
Try
Call bukakoneksi()
tampil2.Connection = database
tampil2.CommandType = CommandType.Text
tampil2.CommandText = "Delete from jurusan where kdjur= '" & Trim(TextBox1.Text)
tampil2.ExecuteNonQuery()
Call kosong()
TextBox1.Focus()
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call simpankelompok()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If Button4.Text = "Keluar" Then
Me.Close()
Else
Call kosong()
Call netral()
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Call ubahkelompok()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Call hapuskelompok()
End Sub
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = Chr(Keys.Enter) Then
If Button1.Text = "Simpan" Then
Call celrecord()
If hasilcek = False Then
TextBox2.Focus()
Else
MsgBox("Kode Sudah ada, silahkan ganti kode lain", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Informasi")
tampilkan = tampil2.ExecuteReader
End If
Else
Call bukakoneksi()
tampil2.Connection = database
tampil2.CommandType = CommandType.Text
tampil2.CommandText = " select* from jurusan where kdjur='" & Trim(TextBox1.Text) & "'"
tampilkan = tampil2.ExecuteReader
If tampilkan.HasRows = True Then
While tampilkan.Read()
If IsDBNull(tampilkan("kdjur")) Then
TextBox1.Focus()
Else
TextBox2.Text = tampilkan("nmjur")
TextBox2.Focus()
End If
End While
Else
MsgBox("Data tidak diketemukan", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Tambah Data")
End If
End If
End If
End Sub
End Class
Buat form berikut:
Kemudian ketikkan coding berikut:
Public Class update
Sub kosong()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox1.Focus()
End Sub
Sub netral()
Button1.Text = "Tambah"
Button2.Text = "Ubah"
Button3.Text = "Hapus"
Button4.Text = "Keluar"
Button1.Enabled = True 'enable=funsi aktif/tdaknya sebuah objek
Button2.Enabled = True
Button3.Enabled = True
Button4.Enabled = True
End Sub
Sub celrecord()
Call bukakoneksi()
tampil2.Connection = database
tampil2.CommandType = CommandType.Text
tampil2.CommandText = "select * from jurusan where kdjur='" & Trim(TextBox1.Text) & "'"
tampilkan = tampil2.ExecuteReader
If tampilkan.HasRows = True Then ''ada atau tidak recod yg dimaksukkan
hasilcek = True
Else
hasilcek = False
End If
End Sub
Sub simpankelompok()
If Button1.Text = "Tambah" Then
TextBox1.Text = ""
Button1.Text = "Simpan"
Button2.Enabled = False
Button3.Enabled = False
Button4.Text = "Batal"
TextBox1.Focus()
Else
If TextBox1.Text = "" Then Exit Sub
If TextBox2.Text = "" Then Exit Sub
End If
Call celrecord()
Try
If hasilcek = False Then
Call bukakoneksi()
tampil2.Connection = database
tampil2.CommandType = CommandType.Text
tampil2.CommandText = "Insert into jurusan (kdjur,nmjur)values('" & TextBox1.Text & "','" & TextBox2.Text & "')"
tampil2.ExecuteNonQuery()
Call kosong()
Else
MsgBox("data sudah ada, silahkan cek data yang diinput", MsgBoxStyle.Critical, "input data") 'critical =! dalam msgbox
End If
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub
Sub ubahkelompok()
If Button2.Text = "Ubah" Then
TextBox1.Text = ""
Button2.Text = "Simpan"
Button1.Enabled = False
Button3.Enabled = False
Button4.Text = "Batal"
TextBox1.Focus()
Else
If TextBox1.Text = "" Then Exit Sub
If TextBox2.Text = "" Then Exit Sub
End If
Try
Call bukakoneksi()
tampil2.Connection = database
tampil2.CommandType = CommandType.Text
tampil2.CommandText = "Update Jurusan set nmjur='" & Trim(TextBox2.Text) & "'where kdjur='" & TextBox1.Text & "'"
tampil2.ExecuteNonQuery()
Call kosong()
TextBox1.Focus()
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub
Sub hapuskelompok()
If Button3.Text = "Hapus" Then
TextBox1.Text = ""
Button3.Text = "OK"
Button1.Enabled = False
Button2.Enabled = False
Button4.Text = "Batal"
TextBox1.Focus()
Else
If TextBox1.Text = "" Then Exit Sub
If TextBox2.Text = "" Then Exit Sub
Try
Call bukakoneksi()
tampil2.Connection = database
tampil2.CommandType = CommandType.Text
tampil2.CommandText = "Delete from jurusan where kdjur= '" & Trim(TextBox1.Text)
tampil2.ExecuteNonQuery()
Call kosong()
TextBox1.Focus()
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call simpankelompok()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If Button4.Text = "Keluar" Then
Me.Close()
Else
Call kosong()
Call netral()
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Call ubahkelompok()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Call hapuskelompok()
End Sub
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = Chr(Keys.Enter) Then
If Button1.Text = "Simpan" Then
Call celrecord()
If hasilcek = False Then
TextBox2.Focus()
Else
MsgBox("Kode Sudah ada, silahkan ganti kode lain", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Informasi")
tampilkan = tampil2.ExecuteReader
End If
Else
Call bukakoneksi()
tampil2.Connection = database
tampil2.CommandType = CommandType.Text
tampil2.CommandText = " select* from jurusan where kdjur='" & Trim(TextBox1.Text) & "'"
tampilkan = tampil2.ExecuteReader
If tampilkan.HasRows = True Then
While tampilkan.Read()
If IsDBNull(tampilkan("kdjur")) Then
TextBox1.Focus()
Else
TextBox2.Text = tampilkan("nmjur")
TextBox2.Focus()
End If
End While
Else
MsgBox("Data tidak diketemukan", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Tambah Data")
End If
End If
End If
End Sub
End Class
MENCARI DATA
Mencari database yang telah kita input:
Buatlah sebuah form berikut :
Kemudian ketik coding berikut :
Public Class cari
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call bukakoneksi()
tampil2.Connection = database
tampil2.CommandType = CommandType.Text
tampil2.CommandText = "select * from jurusan where kdjur='" & Trim(TextBox1.Text) & "'"
tampilkan = tampil2.ExecuteReader
If tampilkan.HasRows = True Then
While tampilkan.Read()
If IsDBNull(tampilkan("kdjur")) Then
TextBox2.Text = tampilkan("nmjur")
Else
TextBox2.Text = tampilkan("nmjur")
End If
End While
End If
End Sub
End Class
Buatlah sebuah form berikut :
Kemudian ketik coding berikut :
Public Class cari
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call bukakoneksi()
tampil2.Connection = database
tampil2.CommandType = CommandType.Text
tampil2.CommandText = "select * from jurusan where kdjur='" & Trim(TextBox1.Text) & "'"
tampilkan = tampil2.ExecuteReader
If tampilkan.HasRows = True Then
While tampilkan.Read()
If IsDBNull(tampilkan("kdjur")) Then
TextBox2.Text = tampilkan("nmjur")
Else
TextBox2.Text = tampilkan("nmjur")
End If
End While
End If
End Sub
End Class
KONEKSI DATABASE
Dalam membuat program kita biasa menggunakan database. Sebagai koneksi kita menggunakan module yang dibuat untuk mengkoneksikan dengan database Membuat modul koneksi dengan database adalah sebagai berikut :
Imports System.Data
Imports System.Data.Sql
Module koneksi
Public database As New OleDb.OleDbConnection
Public tampil2 As New OleDb.OleDbCommand
Public tampilkan As OleDb.OleDbDataReader
Public hasilcek As String
Public Sub bukakoneksi()
database.Close()
Try
database.ConnectionString = "provider=sqloledb.1;integrated security=SSPI;persist security info=false; initial catalog=cobasql;data source=."
database.Open()
MessageBox.Show("Koneksi kedatabase berhasil")
Catch ex As Exception
MessageBox.Show("koneksi gagal")
End
End Try
End Sub
End Module
kemudian membuat tampilan formnya sebagai berikut ;
Kemudian membuat sintax seperti ini dalam form yang baru.
Public Class Form2
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call bukakoneksi()
tampil2.Connection = database
tampil2.CommandType = CommandType.Text
tampil2.CommandText = "select * from jurusan where kdjur='" & Trim(TextBox1.Text) & "'"
tampilkan = tampil2.ExecuteReader
If tampilkan.HasRows = True Then
While tampilkan.Read()
If IsDBNull(tampilkan("kdjur")) Then
TextBox2.text = tampilkan("nmjur")
Else
TextBox2.Text = tampilkan("nmjur")
End If
End While
End If
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
End Class
kemudian membuat tampilan formnya lagi sebagai berikut :
Dan dilanjutkan dengan membuat sintax selanjutnya pada form baru selanjutnya ;
Public Class Form2
Sub kosong()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox1.Focus()
End Sub
Sub netral()
Button1.Text = "Tambah"
Button2.Text = "Ubah"
Button3.Text = "Hapus"
Button4.Text = "Keluar"
Button1.Enabled = True 'enable=funsi aktif/tdaknya sebuah objek
Button2.Enabled = True
Button3.Enabled = True
Button4.Enabled = True
End Sub
Sub celrecord()
Call bukakoneksi()
tampil2.Connection = database
tampil2.CommandType = CommandType.Text
tampil2.CommandText = "select * from jurusan where kdjur='" & Trim(TextBox1.Text) & "'"
tampilkan = tampil2.ExecuteReader
If tampilkan.HasRows = True Then ''ada atau tidak recod yg dimaksukkan
hasilcek = True
Else
hasilcek = False
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call simpankelompok()
End Sub
Sub simpankelompok()
If Button1.Text = "Tambah" Then
TextBox1.Text = ""
Button1.Text = "Simpan"
Button2.Enabled = False
Button3.Enabled = False
Button4.Text = "Batal"
TextBox1.Focus()
Else
If TextBox1.Text = "" Then Exit Sub ''then exit sub = keluar dari sub class dgan syarat textbox harus diisi/pengecekan validasi
If TextBox2.Text = "" Then Exit Sub
Call celrecord()
Try
If hasilcek = "False" Then
Call bukakoneksi()
tampil2.Connection = database
tampil2.CommandType = CommandType.Text
tampil2.CommandText = " Insert into Jurusan (kdjur,nmjur)values ('" & TextBox1.Text & "','" & TextBox2.Text & "')"
tampil2.ExecuteNonQuery()
Call kosong()
Else
MsgBox("Data sudah ada , silahkan cek data yang akan diinput ", MsgBoxStyle.Critical, "Input data") ''critical = ! dalam msgbox
End If
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If Button4.Text = "Keluar" Then
Me.Close()
Else
Call kosong()
Call netral()
End If
End Sub
Sub ubahkelompok()
If Button2.Text = "Ubah" Then
TextBox1.Text = ""
Button2.Text = "Simpan"
Button1.Enabled = False
Button3.Enabled = False
Button4.Text = "Batal"
TextBox1.Focus()
Else
If TextBox1.Text = "" Then Exit Sub ''then exit sub = keluar dari sub class dgan syarat textbox harus diisi/pengecekan validasi
If TextBox2.Text = "" Then Exit Sub
Try
Call bukakoneksi()
tampil2.Connection = database
tampil2.CommandType = CommandType.Text
tampil2.CommandText = " Update Jurusan set nmjur='" & TextBox2.Text & "'where kdjur='" & TextBox1.Text & "'"
tampil2.ExecuteNonQuery()
Call kosong()
TextBox1.Focus()
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Call ubahkelompok()
End Sub
Sub hapuskelompok()
If Button3.Text = "Hapus" Then
TextBox1.Text = " "
Button3.Text = "Ok"
Button1.Enabled = False
Button2.Enabled = False
Button4.Text = "Batal"
TextBox1.Focus()
Else
If TextBox1.Text = "" Then Exit Sub
If TextBox2.Text = "" Then Exit Sub
Try
Call bukakoneksi()
tampil2.Connection = database
tampil2.CommandType = CommandType.Text
tampil2.CommandText = " Delete from Jurusan where kdjur='" & Trim(TextBox1.Text)&"'"
tampil2.ExecuteNonQuery()
Call kosong()
TextBox1.Focus()
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Call hapuskelompok()
End Sub
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = Chr(Keys.Enter) Then
If Button1.Text = "Simpan" Then
Call celrecord()
If hasilcek = False Then
TextBox2.Focus()
Else
MsgBox("Kode Sudah ada, silahkan ganti kode lain", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Informasi")
tampilkan = tampil2.ExecuteReader
End If
Else
Call bukakoneksi()
tampil2.Connection = database
tampil2.CommandType = CommandType.Text
tampil2.CommandText = " select* from Jurusan where kdjur='" & Trim(TextBox1.Text) & "'"
tampil2.ExecuteNonQuery()
If tampilkan.HasRows = True Then
While tampilkan.Read()
If (IsDBNull(tampilkan("kdjur"))) Then
TextBox1.Focus()
Else
TextBox2.Text = tampilkan("nmjur")
TextBox2.Focus()
End If
End While
Else
MsgBox("Data tidak diketemukan", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Tambah Data")
End If
End If
End If
End Sub
End Class
maka program selesai dan jangan lupa dibuat database terlebih dahulu dengan menggunakan SQL Server 2000. Untuk keterangan selanjutnya akan dibahas pada posting / update yang akan datang berikutnya…… tunggu tanggal mainnya….
Imports System.Data
Imports System.Data.Sql
Module koneksi
Public database As New OleDb.OleDbConnection
Public tampil2 As New OleDb.OleDbCommand
Public tampilkan As OleDb.OleDbDataReader
Public hasilcek As String
Public Sub bukakoneksi()
database.Close()
Try
database.ConnectionString = "provider=sqloledb.1;integrated security=SSPI;persist security info=false; initial catalog=cobasql;data source=."
database.Open()
MessageBox.Show("Koneksi kedatabase berhasil")
Catch ex As Exception
MessageBox.Show("koneksi gagal")
End
End Try
End Sub
End Module
kemudian membuat tampilan formnya sebagai berikut ;
Kemudian membuat sintax seperti ini dalam form yang baru.
Public Class Form2
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call bukakoneksi()
tampil2.Connection = database
tampil2.CommandType = CommandType.Text
tampil2.CommandText = "select * from jurusan where kdjur='" & Trim(TextBox1.Text) & "'"
tampilkan = tampil2.ExecuteReader
If tampilkan.HasRows = True Then
While tampilkan.Read()
If IsDBNull(tampilkan("kdjur")) Then
TextBox2.text = tampilkan("nmjur")
Else
TextBox2.Text = tampilkan("nmjur")
End If
End While
End If
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
End Class
kemudian membuat tampilan formnya lagi sebagai berikut :
Dan dilanjutkan dengan membuat sintax selanjutnya pada form baru selanjutnya ;
Public Class Form2
Sub kosong()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox1.Focus()
End Sub
Sub netral()
Button1.Text = "Tambah"
Button2.Text = "Ubah"
Button3.Text = "Hapus"
Button4.Text = "Keluar"
Button1.Enabled = True 'enable=funsi aktif/tdaknya sebuah objek
Button2.Enabled = True
Button3.Enabled = True
Button4.Enabled = True
End Sub
Sub celrecord()
Call bukakoneksi()
tampil2.Connection = database
tampil2.CommandType = CommandType.Text
tampil2.CommandText = "select * from jurusan where kdjur='" & Trim(TextBox1.Text) & "'"
tampilkan = tampil2.ExecuteReader
If tampilkan.HasRows = True Then ''ada atau tidak recod yg dimaksukkan
hasilcek = True
Else
hasilcek = False
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call simpankelompok()
End Sub
Sub simpankelompok()
If Button1.Text = "Tambah" Then
TextBox1.Text = ""
Button1.Text = "Simpan"
Button2.Enabled = False
Button3.Enabled = False
Button4.Text = "Batal"
TextBox1.Focus()
Else
If TextBox1.Text = "" Then Exit Sub ''then exit sub = keluar dari sub class dgan syarat textbox harus diisi/pengecekan validasi
If TextBox2.Text = "" Then Exit Sub
Call celrecord()
Try
If hasilcek = "False" Then
Call bukakoneksi()
tampil2.Connection = database
tampil2.CommandType = CommandType.Text
tampil2.CommandText = " Insert into Jurusan (kdjur,nmjur)values ('" & TextBox1.Text & "','" & TextBox2.Text & "')"
tampil2.ExecuteNonQuery()
Call kosong()
Else
MsgBox("Data sudah ada , silahkan cek data yang akan diinput ", MsgBoxStyle.Critical, "Input data") ''critical = ! dalam msgbox
End If
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If Button4.Text = "Keluar" Then
Me.Close()
Else
Call kosong()
Call netral()
End If
End Sub
Sub ubahkelompok()
If Button2.Text = "Ubah" Then
TextBox1.Text = ""
Button2.Text = "Simpan"
Button1.Enabled = False
Button3.Enabled = False
Button4.Text = "Batal"
TextBox1.Focus()
Else
If TextBox1.Text = "" Then Exit Sub ''then exit sub = keluar dari sub class dgan syarat textbox harus diisi/pengecekan validasi
If TextBox2.Text = "" Then Exit Sub
Try
Call bukakoneksi()
tampil2.Connection = database
tampil2.CommandType = CommandType.Text
tampil2.CommandText = " Update Jurusan set nmjur='" & TextBox2.Text & "'where kdjur='" & TextBox1.Text & "'"
tampil2.ExecuteNonQuery()
Call kosong()
TextBox1.Focus()
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Call ubahkelompok()
End Sub
Sub hapuskelompok()
If Button3.Text = "Hapus" Then
TextBox1.Text = " "
Button3.Text = "Ok"
Button1.Enabled = False
Button2.Enabled = False
Button4.Text = "Batal"
TextBox1.Focus()
Else
If TextBox1.Text = "" Then Exit Sub
If TextBox2.Text = "" Then Exit Sub
Try
Call bukakoneksi()
tampil2.Connection = database
tampil2.CommandType = CommandType.Text
tampil2.CommandText = " Delete from Jurusan where kdjur='" & Trim(TextBox1.Text)&"'"
tampil2.ExecuteNonQuery()
Call kosong()
TextBox1.Focus()
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Call hapuskelompok()
End Sub
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = Chr(Keys.Enter) Then
If Button1.Text = "Simpan" Then
Call celrecord()
If hasilcek = False Then
TextBox2.Focus()
Else
MsgBox("Kode Sudah ada, silahkan ganti kode lain", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Informasi")
tampilkan = tampil2.ExecuteReader
End If
Else
Call bukakoneksi()
tampil2.Connection = database
tampil2.CommandType = CommandType.Text
tampil2.CommandText = " select* from Jurusan where kdjur='" & Trim(TextBox1.Text) & "'"
tampil2.ExecuteNonQuery()
If tampilkan.HasRows = True Then
While tampilkan.Read()
If (IsDBNull(tampilkan("kdjur"))) Then
TextBox1.Focus()
Else
TextBox2.Text = tampilkan("nmjur")
TextBox2.Focus()
End If
End While
Else
MsgBox("Data tidak diketemukan", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Tambah Data")
End If
End If
End If
End Sub
End Class
maka program selesai dan jangan lupa dibuat database terlebih dahulu dengan menggunakan SQL Server 2000. Untuk keterangan selanjutnya akan dibahas pada posting / update yang akan datang berikutnya…… tunggu tanggal mainnya….
Cristal Report VB.Net
LANGKAH DALAM MEMBUAT CRISTAL REPORT DALAM VB.NET
Langsung saja pada, inti dari tutorial yang Saya ( Robby ) buat. Simak baik-baik………
Untuk membuat report langkah yang harusa kita lakukan adalah
• Klik Kanan pada project yang dibuat -> Add-> New Item
• Kemudian pilih Reporting-> Cristal Report
• Maka akan muncul tampilan seperti berikut.
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidVjefh-JyRvkigqal5Z8vFl1t4eplrGIMWa6kcNedYbeZPkdsJcf2L7OGze2PVR6QaazbIVy3UZjEH0igSl7FltbQxwb_QqVadsY07nO5m4wlllF2xzrLYWlblsGa1ltyjhkUUyE318I/s320/1.bmp
• Kemudian pilih ok
• Lakukan langkah berikut. Pilih Create New Connection-> Ole Db (Ado)
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieeSc2xcEG3ZF-A1tmD8y607AIkzxUT1bvHmyTrbPIfVuqiW-vNrfqOcLS37OToFPlGxo4oiIz-MFloUPTwTdm0u61oKK7bRPTRCZVN8gINPpLMW3X4gqEtILp6Jr__aTj7_owNBMuLjg/s320/2.bmp
• Maka muncul tampilan seperti ini
• Dan pilih “Microsoft Ole DB Provider for SQL Server” karena yang akan kita gunakan adalah database dengan menggunakan Microsoft SQL Server 2000.
• Klik next
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi01P00zr-r02CasfzKPItyhKpv75sef17-4gDUj6jeZdn3rQjydmXHL-uwVpr85xWNOSjYLoYDqpbzwExnzxngDfl-w8CREJH6voqGGneMEX_bCAV7Py29HNa6GqyWI1hfP5LAMsysir8/s320/3.bmp
• Dan muncul lagi yang demikian
• Untuk penggunaan server jika local isi dengan titik saja, ceklist pada integrated security dan pilih data base yang telah kita buat sebelumnya pada Microsoft SQL Server.
• Kemudian klik next-> finish
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEil1il8uUelzvqN2yiW5rsPNDrRoqT0jq1TfjFdGD9Qvn5SLR1J-APTgvKNdC4zlBonT6oOXPTwshWpEE8nviIWGlLbP93DfirvCGjAyHAw2_JLRNa2VRO5ba3uBOpfv9UN8zv_8zaT4zg/s320/4.bmp
• Akan muncul kaya gini
• Sekarang database Jurusan telah muncul dan kita tinggal pilih tablenya seperti pada gambar
• Klik next
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimVd14E3lA79SFfe1P65qUdydIzNVm7lnPu8XXXJFxoDYbfTyD4SZHdBqPqh18lpm4aiI3u0ETz-S48xzf_XOUzYYhHEbZHIf_5ya_EEPSE8giRQz6B0EcVN7b396_5ZukKt8k1mv7S1k/s320/5.bmp
• Muncul seperti ini
• Klik pilihan “>>” untuk menentukan field mana yang akan dimunculkan pada report nanti.
• Klik next
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifvtjlSLhDuWlaTCIl9uFUJWswHPBX8rDgNB_ZX0arPJW9GVXJdYTi3XgqkDZ7bg1nKbbOM4ONVSM_ZbE8muvN4UlpV7ngM3XmX1mBC-Kl8AOv12_MEPB4MBP3ALfRrkDX5wo2OMCfrZA/s320/6.bmp
• Kemudian next
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0rm4kZUkIZsTIEIyS1bC9mVCzX-RXAbo7M6O4EwGIVi9xxkCtLNnFmUIqm5N3NQpLbjAayzbwxm6qG2Ra-K2rmBmFH9noq52dAPuzZnwuk59nBHqBUIKPZvZnaa_lq7MelrRf6SwXYp0/s320/7.bmp
• Klik next lagi
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxwFv7FxjmHw8WywmhyphenhyphenfJKvHZTMreV0y12HOBBdYNSYZ3K4ep3HS2_wDap-HTU9arH2HIW7egr-gJONNHpzRQbW7scKcICmkJEsZHB-AaQiPoYp0Ez2APLdGhXY9dzE2CflkJ_AP0DOkw/s320/8.bmp
• Kemudian pilih tampilan report yang menarik dan sesuai dengan kebutuhannya.
• Lalu klik finish
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGdU8M5_VDRljEto3WQjiP3_8C8-T93-98O0vOt3bOZjn6gpgmlwV0W8_B0UjEHiyncAXtpM5lNIIKz8YiTB_8fpoiaCpKJ10n3_t0I6pNMJNzeR8cN397AvGjbladB9eGOZCI3gavD9M/s320/9.bmp
• Maka akan muncul seperti ini, kemudian kita klik kanan “Preview Report”
•
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgcIrT_C9R3EP5S1uSqUNDlSI7N3LJ3_tnxW3KsS-lzLYkCHZwfLkUzjBh9N0OYbkvsI-IZ5gp9WWUPk7NbNNzpJA4ehALA-pqPDPysZmfBr3IXohjZlOIQCYNe4znpHMdakvUf8l18O08/s320/10.bmp
• Maka hasil akan tampil seperti ini :
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuJXFaKVXB4w2QQY-V7ny-LyInRmNpnRqdbbyruGiJtRsO_CpqmlxUg5H_4qQJJsLxEtLeebJsG7xs4PeQZFo4LrVzMYhH4SHBA3Lde0pk4VCrDjQLbSkkEWHGLRtMlPe4Y2OKtnqHZ_M/s320/11.bmp
• Kemudian buat form baru yang akan digunakan untuk menampilkan report tersebut
• Klik kanan pada project-> add-> windows form….
• Pilih di toolbox berupa “Cristal Report Viewer”
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMivPnvfH827ygKtBTlB-cUjifONQqX70pbHdxKpdJoKr1t8gsL2eP40SfMpzf48397TnP8Mdn81gtO3VXTexA63jEHnOan7bbAW-Pm1EY31OlS3qE0LCFE5cTcPtkRI5G3xlb-wdLgjk/s320/12.bmp
• Kemudian klik kanan dan pilih “choose a cristal report”
• Pilih cristal report yang akan dilihat lalu klik Ok.
• Lalu running form tersebut, maka akan muncul yang kira-kira seperti ini :
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgT_m08zujAR6ElpuWE-WaAynKUfPAaKdCOb9LHyxjFUyhwd_wL9twIjz-dJ50p94t5vukfn0sg4XBz48nRl3DKSPzCKQOVlbz7HooysaByLGvlYDJ1gI1wgDRTt9O4d3kOB-Rh8IX3lvM/s320/13.bmp
• Sangat dibutuhkan ada kekurangan kritik atau saran yang membangun.
• Terima kasih…. Selamat Mencoba……………
Langsung saja pada, inti dari tutorial yang Saya ( Robby ) buat. Simak baik-baik………
Untuk membuat report langkah yang harusa kita lakukan adalah
• Klik Kanan pada project yang dibuat -> Add-> New Item
• Kemudian pilih Reporting-> Cristal Report
• Maka akan muncul tampilan seperti berikut.
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidVjefh-JyRvkigqal5Z8vFl1t4eplrGIMWa6kcNedYbeZPkdsJcf2L7OGze2PVR6QaazbIVy3UZjEH0igSl7FltbQxwb_QqVadsY07nO5m4wlllF2xzrLYWlblsGa1ltyjhkUUyE318I/s320/1.bmp
• Kemudian pilih ok
• Lakukan langkah berikut. Pilih Create New Connection-> Ole Db (Ado)
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieeSc2xcEG3ZF-A1tmD8y607AIkzxUT1bvHmyTrbPIfVuqiW-vNrfqOcLS37OToFPlGxo4oiIz-MFloUPTwTdm0u61oKK7bRPTRCZVN8gINPpLMW3X4gqEtILp6Jr__aTj7_owNBMuLjg/s320/2.bmp
• Maka muncul tampilan seperti ini
• Dan pilih “Microsoft Ole DB Provider for SQL Server” karena yang akan kita gunakan adalah database dengan menggunakan Microsoft SQL Server 2000.
• Klik next
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi01P00zr-r02CasfzKPItyhKpv75sef17-4gDUj6jeZdn3rQjydmXHL-uwVpr85xWNOSjYLoYDqpbzwExnzxngDfl-w8CREJH6voqGGneMEX_bCAV7Py29HNa6GqyWI1hfP5LAMsysir8/s320/3.bmp
• Dan muncul lagi yang demikian
• Untuk penggunaan server jika local isi dengan titik saja, ceklist pada integrated security dan pilih data base yang telah kita buat sebelumnya pada Microsoft SQL Server.
• Kemudian klik next-> finish
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEil1il8uUelzvqN2yiW5rsPNDrRoqT0jq1TfjFdGD9Qvn5SLR1J-APTgvKNdC4zlBonT6oOXPTwshWpEE8nviIWGlLbP93DfirvCGjAyHAw2_JLRNa2VRO5ba3uBOpfv9UN8zv_8zaT4zg/s320/4.bmp
• Akan muncul kaya gini
• Sekarang database Jurusan telah muncul dan kita tinggal pilih tablenya seperti pada gambar
• Klik next
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimVd14E3lA79SFfe1P65qUdydIzNVm7lnPu8XXXJFxoDYbfTyD4SZHdBqPqh18lpm4aiI3u0ETz-S48xzf_XOUzYYhHEbZHIf_5ya_EEPSE8giRQz6B0EcVN7b396_5ZukKt8k1mv7S1k/s320/5.bmp
• Muncul seperti ini
• Klik pilihan “>>” untuk menentukan field mana yang akan dimunculkan pada report nanti.
• Klik next
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifvtjlSLhDuWlaTCIl9uFUJWswHPBX8rDgNB_ZX0arPJW9GVXJdYTi3XgqkDZ7bg1nKbbOM4ONVSM_ZbE8muvN4UlpV7ngM3XmX1mBC-Kl8AOv12_MEPB4MBP3ALfRrkDX5wo2OMCfrZA/s320/6.bmp
• Kemudian next
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0rm4kZUkIZsTIEIyS1bC9mVCzX-RXAbo7M6O4EwGIVi9xxkCtLNnFmUIqm5N3NQpLbjAayzbwxm6qG2Ra-K2rmBmFH9noq52dAPuzZnwuk59nBHqBUIKPZvZnaa_lq7MelrRf6SwXYp0/s320/7.bmp
• Klik next lagi
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxwFv7FxjmHw8WywmhyphenhyphenfJKvHZTMreV0y12HOBBdYNSYZ3K4ep3HS2_wDap-HTU9arH2HIW7egr-gJONNHpzRQbW7scKcICmkJEsZHB-AaQiPoYp0Ez2APLdGhXY9dzE2CflkJ_AP0DOkw/s320/8.bmp
• Kemudian pilih tampilan report yang menarik dan sesuai dengan kebutuhannya.
• Lalu klik finish
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGdU8M5_VDRljEto3WQjiP3_8C8-T93-98O0vOt3bOZjn6gpgmlwV0W8_B0UjEHiyncAXtpM5lNIIKz8YiTB_8fpoiaCpKJ10n3_t0I6pNMJNzeR8cN397AvGjbladB9eGOZCI3gavD9M/s320/9.bmp
• Maka akan muncul seperti ini, kemudian kita klik kanan “Preview Report”
•
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgcIrT_C9R3EP5S1uSqUNDlSI7N3LJ3_tnxW3KsS-lzLYkCHZwfLkUzjBh9N0OYbkvsI-IZ5gp9WWUPk7NbNNzpJA4ehALA-pqPDPysZmfBr3IXohjZlOIQCYNe4znpHMdakvUf8l18O08/s320/10.bmp
• Maka hasil akan tampil seperti ini :
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuJXFaKVXB4w2QQY-V7ny-LyInRmNpnRqdbbyruGiJtRsO_CpqmlxUg5H_4qQJJsLxEtLeebJsG7xs4PeQZFo4LrVzMYhH4SHBA3Lde0pk4VCrDjQLbSkkEWHGLRtMlPe4Y2OKtnqHZ_M/s320/11.bmp
• Kemudian buat form baru yang akan digunakan untuk menampilkan report tersebut
• Klik kanan pada project-> add-> windows form….
• Pilih di toolbox berupa “Cristal Report Viewer”
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMivPnvfH827ygKtBTlB-cUjifONQqX70pbHdxKpdJoKr1t8gsL2eP40SfMpzf48397TnP8Mdn81gtO3VXTexA63jEHnOan7bbAW-Pm1EY31OlS3qE0LCFE5cTcPtkRI5G3xlb-wdLgjk/s320/12.bmp
• Kemudian klik kanan dan pilih “choose a cristal report”
• Pilih cristal report yang akan dilihat lalu klik Ok.
• Lalu running form tersebut, maka akan muncul yang kira-kira seperti ini :
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgT_m08zujAR6ElpuWE-WaAynKUfPAaKdCOb9LHyxjFUyhwd_wL9twIjz-dJ50p94t5vukfn0sg4XBz48nRl3DKSPzCKQOVlbz7HooysaByLGvlYDJ1gI1wgDRTt9O4d3kOB-Rh8IX3lvM/s320/13.bmp
• Sangat dibutuhkan ada kekurangan kritik atau saran yang membangun.
• Terima kasih…. Selamat Mencoba……………
MEMBUAT FORM LOGIN
Berikut adalah cara untuk membuat login pada VB.net
• Membuat login pada VB.net
• Klik kanan pada project yang dibuat
• Add -> New item-> login form
• Klik 2x pada tombol ok
• Masukan sintax
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
If UsernameTextBox.Text = "robby" And PasswordTextBox.Text = "ganteng" Then
MDIParent1.Show()
Me.Visible = False
Else
MsgBox("login gagal,coba ulangi lagi")
End If
End Sub
* Lalu jalankan / running program tersebut
* Masukan username “robby” dan password “ganteng”
• Jika sudah bisa login dan muncul MDI Parent Form maka Login telah selesai.
• Selamat mencoba……
• Membuat login pada VB.net
• Klik kanan pada project yang dibuat
• Add -> New item-> login form
• Klik 2x pada tombol ok
• Masukan sintax
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
If UsernameTextBox.Text = "robby" And PasswordTextBox.Text = "ganteng" Then
MDIParent1.Show()
Me.Visible = False
Else
MsgBox("login gagal,coba ulangi lagi")
End If
End Sub
* Lalu jalankan / running program tersebut
* Masukan username “robby” dan password “ganteng”
• Jika sudah bisa login dan muncul MDI Parent Form maka Login telah selesai.
• Selamat mencoba……
Minggu, 17 April 2011
uts april 2011
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
Dim a, b, m, n As Integer
a = Val(TextBox1.Text)
b = Val(TextBox2.Text)
For n = Val(TextBox1.Text) To Val(TextBox2.Text)
If n Mod 2 = 0 And n Mod 1 = 0 Then
ListBox1.Items.Add(n)
End If
Next
For i = a To b
If i Mod a = 0 Then
ListBox2.Items.Add(i)
a = i
End If
Next
For m = a To b
If m Mod b = 0 Then
ListBox2.Items.Add(m)
b = m
End If
Next
End Sub
Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged
Next
End Sub
End Class
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
Dim a, b, m, n As Integer
a = Val(TextBox1.Text)
b = Val(TextBox2.Text)
For n = Val(TextBox1.Text) To Val(TextBox2.Text)
If n Mod 2 = 0 And n Mod 1 = 0 Then
ListBox1.Items.Add(n)
End If
Next
For i = a To b
If i Mod a = 0 Then
ListBox2.Items.Add(i)
a = i
End If
Next
For m = a To b
If m Mod b = 0 Then
ListBox2.Items.Add(m)
b = m
End If
Next
End Sub
Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged
Next
End Sub
End Class
Sabtu, 16 April 2011
thank's before buat Temen saya ini, cz saya copy dari blog dia,, pinjem bentar ya prenn,, buat ujian..
buat dulu design kaya gini :
Lalu ubah "Nama" Button 1 menjadi "3" dengan merubah pada propertiesnya :
Lakukan Hal yang sama untuk Button Lain, Seperti Berikut :
button2 textnya menjadi =5
button3 textnya menjadi =6
button4 textnya menjadi =2
button5 textnya menjadi =1
button6 textnya menjadi =7
button7 textnya menjadi =8
button8 textnya menjadi =4
sedangkan button9
button9 menjadi visible = false *,seperti:
kemudian, masukkan coding berikut & sesuaikan dengan button awal (nomor yang normal ):
Public Class Form1
(button1):
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Button2.Visible = False Then
Button2.Visible = True
Button1.Visible = False
Button2.Text = Button1.Text
Else
If Button4.Visible = False Then
Button4.Visible = True
Button1.Visible = False
Button4.Text = Button1.Text
End If
End If
kerja()
End Sub
(button2):
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If Button1.Visible = False Then
Button1.Visible = True
Button2.Visible = False
Button1.Text = Button2.Text
ElseIf Button3.Visible = False Then
Button3.Visible = True
Button2.Visible = False
Button3.Text = Button2.Text
ElseIf Button5.Visible = False Then
Button2.Visible = True
Button5.Visible = False
Button5.Text = Button2.Text
End If
kerja()
End Sub
(button3):
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If Button2.Visible = False Then
Button2.Visible = True
Button3.Visible = False
Button2.Text = Button3.Text
Else
If Button6.Visible = False Then
Button6.Visible = True
Button3.Visible = False
Button6.Text = Button3.Text
End If
End If
End Sub
(button4):
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If Button1.Visible = False Then
Button1.Visible = True
Button4.Visible = False
Button1.Text = Button4.Text
ElseIf Button5.Visible = False Then
Button5.Visible = True
Button4.Visible = False
Button5.Text = Button4.Text
ElseIf Button7.Visible = False Then
Button7.Visible = True
Button4.Visible = False
Button7.Text = Button4.Text
End If
kerja()
End Sub
(button5):
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
If Button2.Visible = False Then
Button2.Visible = True
Button5.Visible = False
Button2.Text = Button5.Text
ElseIf Button4.Visible = False Then
Button4.Visible = True
Button5.Visible = False
Button4.Text = Button5.Text
ElseIf Button6.Visible = False Then
Button6.Visible = True
Button5.Visible = False
Button6.Text = Button5.Text
ElseIf Button8.Visible = False Then
Button8.Visible = True
Button5.Visible = False
Button8.Text = Button5.Text
End If
kerja()
End Sub
(button6):
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
If Button3.Visible = False Then
Button3.Visible = True
Button6.Visible = False
Button3.Text = Button6.Text
ElseIf Button9.Visible = False Then
Button9.Visible = True
Button6.Visible = False
Button9.Text = Button6.Text
ElseIf Button5.Visible = False Then
Button5.Visible = True
Button6.Visible = False
Button5.Text = Button6.Text
End If
kerja()
End Sub
(button7):
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
If Button8.Visible = False Then
Button8.Visible = True
Button7.Visible = False
Button8.Text = Button7.Text
Else
If Button4.Visible = False Then
Button4.Visible = True
Button7.Visible = False
Button4.Text = Button7.Text
End If
End If
kerja()
End Sub
(button8):
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
If Button7.Visible = False Then
Button7.Visible = True
Button8.Visible = False
Button7.Text = Button8.Text
ElseIf Button9.Visible = False Then
Button9.Visible = True
Button8.Visible = False
Button9.Text = Button8.Text
ElseIf Button5.Visible = False Then
Button5.Visible = True
Button8.Visible = False
Button5.Text = Button8.Text
End If
kerja()
End Sub
(button9):
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
If Button6.Visible = False Then
Button6.Visible = True
Button9.Visible = False
Button6.Text = Button9.Text
Else
If Button8.Visible = False Then
Button8.Visible = True
Button9.Visible = False
Button8.Text = Button9.Text
End If
End If
kerja()
End Sub
setelah selesai mengisi printah dari setiap button tersebut sekarang kita tambah methotnya :
Private Sub kerja()
If (Button1.Text = "1" And Button2.Text = "2" And Button3.Text = "3" And Button4.Text = "4") Then
If (Button5.Text = "5" And Button6.Text = "6" And Button7.Text = "7") Then
If (Button8.Text = "8") Then
MessageBox.Show(" selamat anda berhasil")
End If
End If
End If
End Sub
End Class
Tinggal di Running Deh... F5 atao Debugging,,,,
nnti button2 tersebut bisa dipindah2in kaya main puzzle..
buat dulu design kaya gini :
Lalu ubah "Nama" Button 1 menjadi "3" dengan merubah pada propertiesnya :
Lakukan Hal yang sama untuk Button Lain, Seperti Berikut :
button2 textnya menjadi =5
button3 textnya menjadi =6
button4 textnya menjadi =2
button5 textnya menjadi =1
button6 textnya menjadi =7
button7 textnya menjadi =8
button8 textnya menjadi =4
sedangkan button9
button9 menjadi visible = false *,seperti:
kemudian, masukkan coding berikut & sesuaikan dengan button awal (nomor yang normal ):
Public Class Form1
(button1):
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Button2.Visible = False Then
Button2.Visible = True
Button1.Visible = False
Button2.Text = Button1.Text
Else
If Button4.Visible = False Then
Button4.Visible = True
Button1.Visible = False
Button4.Text = Button1.Text
End If
End If
kerja()
End Sub
(button2):
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If Button1.Visible = False Then
Button1.Visible = True
Button2.Visible = False
Button1.Text = Button2.Text
ElseIf Button3.Visible = False Then
Button3.Visible = True
Button2.Visible = False
Button3.Text = Button2.Text
ElseIf Button5.Visible = False Then
Button2.Visible = True
Button5.Visible = False
Button5.Text = Button2.Text
End If
kerja()
End Sub
(button3):
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If Button2.Visible = False Then
Button2.Visible = True
Button3.Visible = False
Button2.Text = Button3.Text
Else
If Button6.Visible = False Then
Button6.Visible = True
Button3.Visible = False
Button6.Text = Button3.Text
End If
End If
End Sub
(button4):
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If Button1.Visible = False Then
Button1.Visible = True
Button4.Visible = False
Button1.Text = Button4.Text
ElseIf Button5.Visible = False Then
Button5.Visible = True
Button4.Visible = False
Button5.Text = Button4.Text
ElseIf Button7.Visible = False Then
Button7.Visible = True
Button4.Visible = False
Button7.Text = Button4.Text
End If
kerja()
End Sub
(button5):
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
If Button2.Visible = False Then
Button2.Visible = True
Button5.Visible = False
Button2.Text = Button5.Text
ElseIf Button4.Visible = False Then
Button4.Visible = True
Button5.Visible = False
Button4.Text = Button5.Text
ElseIf Button6.Visible = False Then
Button6.Visible = True
Button5.Visible = False
Button6.Text = Button5.Text
ElseIf Button8.Visible = False Then
Button8.Visible = True
Button5.Visible = False
Button8.Text = Button5.Text
End If
kerja()
End Sub
(button6):
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
If Button3.Visible = False Then
Button3.Visible = True
Button6.Visible = False
Button3.Text = Button6.Text
ElseIf Button9.Visible = False Then
Button9.Visible = True
Button6.Visible = False
Button9.Text = Button6.Text
ElseIf Button5.Visible = False Then
Button5.Visible = True
Button6.Visible = False
Button5.Text = Button6.Text
End If
kerja()
End Sub
(button7):
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
If Button8.Visible = False Then
Button8.Visible = True
Button7.Visible = False
Button8.Text = Button7.Text
Else
If Button4.Visible = False Then
Button4.Visible = True
Button7.Visible = False
Button4.Text = Button7.Text
End If
End If
kerja()
End Sub
(button8):
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
If Button7.Visible = False Then
Button7.Visible = True
Button8.Visible = False
Button7.Text = Button8.Text
ElseIf Button9.Visible = False Then
Button9.Visible = True
Button8.Visible = False
Button9.Text = Button8.Text
ElseIf Button5.Visible = False Then
Button5.Visible = True
Button8.Visible = False
Button5.Text = Button8.Text
End If
kerja()
End Sub
(button9):
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
If Button6.Visible = False Then
Button6.Visible = True
Button9.Visible = False
Button6.Text = Button9.Text
Else
If Button8.Visible = False Then
Button8.Visible = True
Button9.Visible = False
Button8.Text = Button9.Text
End If
End If
kerja()
End Sub
setelah selesai mengisi printah dari setiap button tersebut sekarang kita tambah methotnya :
Private Sub kerja()
If (Button1.Text = "1" And Button2.Text = "2" And Button3.Text = "3" And Button4.Text = "4") Then
If (Button5.Text = "5" And Button6.Text = "6" And Button7.Text = "7") Then
If (Button8.Text = "8") Then
MessageBox.Show(" selamat anda berhasil")
End If
End If
End If
End Sub
End Class
Tinggal di Running Deh... F5 atao Debugging,,,,
nnti button2 tersebut bisa dipindah2in kaya main puzzle..
List view untuk menampilkan data secara manual
Maret 2011
BELAJAR LISTVIEW!!!
Pada tampilan ini ada 5 button dengan Coding pada tiap – tiap button :
a. Button1 = Save
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click “Event yang kita berikan
If Button1.Text = "SAVE" Then
Button1.Text = "TAMBAH"
Button2.Enabled = "false"
Button3.Enabled = "false"
Button4.Text = "BATAL"
Button5.Text = "FIND"
TextBox1.Focus() “Kursor akan otomatis pada Textbox1
Else
isitext(0) = Trim(TextBox1.Text)
isitext(1) = Trim(TextBox2.Text)
isitext(2) = Trim(TextBox3.Text)
item = New ListViewItem(isitext)
ListView1.Items.Add(item) “ data akan ditampilkan pada ListView
Call bersih()
TextBox1.Focus()
End If
Disinilah terjadi pengaturan Enable yaitu tampilan button pada saat diberikan event klik, apakah button akan muncul jika Enable = True dan button akan tidak muncul jika Enable = False . Dengan focus kursor pada Textbox1.
Untuk Sintak isitext(0) = Trim (TextBox1.Text) dengan ketentuan bahwa Array pada kolom pertama di ListView akan diisi oleh data yang berada pada Textbox 1, yang perlu diingat bahwa array dimulai dengan angka 0. Begitu seterusnya sampai pada array kolom yang diinginkan, jangan Lupa untuk mendeklarasikan Array pada kolom ListView terlebih dahulu pada awal Sintak Class.
Dim isitext(3) As String
Yang berarti isitext = nama array ; (3) = jumlah array / kolom ; As string = Tipe data adalah string. Deklarasi yang lain adalah
Dim item As ListViewItem
Yang berarti item adalah nama item – item yang akan muncul pada ListView
Call bersih()
Pada sintak diatas berarti bahwa kita memanggil method bersih yang sebelum telah kita buat pada Sub Class bersih.
Sub bersih()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
End Sub
Yang berarti pada kondisi bersih maka isi pada tiap – tiap Textbox akan kosong atau tidak ada data didalamnya.
Pada Form ini jangan lupa untuk buat Sub yang berisi tampilan pada ListView. Tampilan ini akn muncul saat Form diaktifkan.
Sub tampilan()
ListView1.View = View.Details
ListView1.Columns.Add("KD_SUPPLIER", 200, HorizontalAlignment.Left)
ListView1.Columns.Add("NM_SUPPLIER", 200, HorizontalAlignment.Left)
ListView1.Columns.Add("ALAMAT", 200, HorizontalAlignment.Left)
End Sub
Pada sub ini berisi nama – nama kolom yang akan muncul pada ListView dengan pengaturan ( Nama kolom , Panjang kolom , jenis tata letak huruf, Letak rata huruf ) .
Sintak ini akan dipanggil ketika mengaktifkan Form dengan cara klik 2 kali pada form dan pilih Event Activated pada kolom event.
Private Sub Data_Supplier_Activated(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Activated
Call bersih()
Call tampilan()
End Sub
b. Button2 = Edit
Pada Button ini hanya terjadi pengaturan Enable yaitu tampilan button pada saat diberikan event klik, apakah button akan muncul jika Enable = True dan button akan tidak muncul jika Enable = False dikarenakan materi yang disampaikan belum pada edit data di database.
If Button2.Text = "EDIT" Then
Button2.Text = "SIMPAN"
Button1.Enabled = "false"
Button3.Enabled = "false"
Button4.Text = "BATAL"
TextBox1.Focus()
End If
c. Button3 = Hapus
Private Sub Button3_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles Button3.Click
Call bersih()
End Sub
Dimana telah dijelaskan sebelumnya tentang method bersih maka pada button ini hanya berisi pemanggilan method beersih untuk mengosongkan isi pada Textbox.
d. Button4 = Keluar
If Button4.Text = "KELUAR" Then
Me.Close()
Else
Call bersih()
Call normal()
End If
Pada button ini dijelaskan jika text pada button “Keluar” maka akan terjadi Me.close yaitu Form akan menutup dengan sendirinya atau keluar dari aplikasi, jika terhubung dengan form Menu maka akan kembali pada form Menu.
Untuk call normal buatlah terlebih dulu Sub pada Class yang sama sub normal dengan isi enable dari tiap – tiap button.
Sub normal()
Button1.Text = "SAVE"
Button1.Enabled = "true"
Button2.Text = "EDIT"
Button2.Enabled = "true"
Button3.Text = "HAPUS"
Button3.Enabled = "true"
Button4.Text = "KELUAR"
Button4.Enabled = "true"
Button5.Text = "FIND"
End Sub
e. Button5 = Find
Pada button ini penulis belum mengisi sintak dikarenakan materi yang belum mencukupi.
Nah Nie Coding utuhnya:
Public Class Data_Supplier
Dim item As ListViewItem
Dim isitext(3) As String
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
End Sub
Private Sub ListView1_ItemSelectionChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.ListViewItemSelectionChangedEventArgs) Handles ListView1.ItemSelectionChanged
TextBox4.Text = e.Item.Text
End Sub
Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
End Sub
Sub tampilan()
ListView1.View = View.Details
ListView1.Columns.Add("KD_SUPPLIER", 200, HorizontalAlignment.Left)
ListView1.Columns.Add("NM_SUPPLIER", 200, HorizontalAlignment.Left)
ListView1.Columns.Add("ALAMAT", 200, HorizontalAlignment.Left)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Button1.Text = "SAVE" Then
Button1.Text = "TAMBAH"
Button2.Enabled = "false"
Button3.Enabled = "false"
Button4.Text = "BATAL"
Button5.Text = "FIND"
TextBox1.Focus()
Else
isitext(0) = Trim(TextBox1.Text)
isitext(1) = Trim(TextBox2.Text)
isitext(2) = Trim(TextBox3.Text)
item = New ListViewItem(isitext)
ListView1.Items.Add(item)
Call bersih()
TextBox1.Focus()
End If
End Sub
Sub normal()
Button1.Text = "SAVE"
Button1.Enabled = "true"
Button2.Text = "EDIT"
Button2.Enabled = "true"
Button3.Text = "HAPUS"
Button3.Enabled = "true"
Button4.Text = "KELUAR"
Button4.Enabled = "true"
Button5.Text = "FIND"
End Sub
Sub bersih()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If Button4.Text = "KELUAR" Then
Me.Close()
Else
Call bersih()
Call normal()
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If Button2.Text = "EDIT" Then
Button2.Text = "SIMPAN"
Button1.Enabled = "false"
Button3.Enabled = "false"
Button4.Text = "BATAL"
TextBox1.Focus()
Else
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Call bersih()
End Sub
Private Sub Data_Supplier_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
Call bersih()
Call tampilan()
End Sub
End Class
BELAJAR LISTVIEW!!!
Pada tampilan ini ada 5 button dengan Coding pada tiap – tiap button :
a. Button1 = Save
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click “Event yang kita berikan
If Button1.Text = "SAVE" Then
Button1.Text = "TAMBAH"
Button2.Enabled = "false"
Button3.Enabled = "false"
Button4.Text = "BATAL"
Button5.Text = "FIND"
TextBox1.Focus() “Kursor akan otomatis pada Textbox1
Else
isitext(0) = Trim(TextBox1.Text)
isitext(1) = Trim(TextBox2.Text)
isitext(2) = Trim(TextBox3.Text)
item = New ListViewItem(isitext)
ListView1.Items.Add(item) “ data akan ditampilkan pada ListView
Call bersih()
TextBox1.Focus()
End If
Disinilah terjadi pengaturan Enable yaitu tampilan button pada saat diberikan event klik, apakah button akan muncul jika Enable = True dan button akan tidak muncul jika Enable = False . Dengan focus kursor pada Textbox1.
Untuk Sintak isitext(0) = Trim (TextBox1.Text) dengan ketentuan bahwa Array pada kolom pertama di ListView akan diisi oleh data yang berada pada Textbox 1, yang perlu diingat bahwa array dimulai dengan angka 0. Begitu seterusnya sampai pada array kolom yang diinginkan, jangan Lupa untuk mendeklarasikan Array pada kolom ListView terlebih dahulu pada awal Sintak Class.
Dim isitext(3) As String
Yang berarti isitext = nama array ; (3) = jumlah array / kolom ; As string = Tipe data adalah string. Deklarasi yang lain adalah
Dim item As ListViewItem
Yang berarti item adalah nama item – item yang akan muncul pada ListView
Call bersih()
Pada sintak diatas berarti bahwa kita memanggil method bersih yang sebelum telah kita buat pada Sub Class bersih.
Sub bersih()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
End Sub
Yang berarti pada kondisi bersih maka isi pada tiap – tiap Textbox akan kosong atau tidak ada data didalamnya.
Pada Form ini jangan lupa untuk buat Sub yang berisi tampilan pada ListView. Tampilan ini akn muncul saat Form diaktifkan.
Sub tampilan()
ListView1.View = View.Details
ListView1.Columns.Add("KD_SUPPLIER", 200, HorizontalAlignment.Left)
ListView1.Columns.Add("NM_SUPPLIER", 200, HorizontalAlignment.Left)
ListView1.Columns.Add("ALAMAT", 200, HorizontalAlignment.Left)
End Sub
Pada sub ini berisi nama – nama kolom yang akan muncul pada ListView dengan pengaturan ( Nama kolom , Panjang kolom , jenis tata letak huruf, Letak rata huruf ) .
Sintak ini akan dipanggil ketika mengaktifkan Form dengan cara klik 2 kali pada form dan pilih Event Activated pada kolom event.
Private Sub Data_Supplier_Activated(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Activated
Call bersih()
Call tampilan()
End Sub
b. Button2 = Edit
Pada Button ini hanya terjadi pengaturan Enable yaitu tampilan button pada saat diberikan event klik, apakah button akan muncul jika Enable = True dan button akan tidak muncul jika Enable = False dikarenakan materi yang disampaikan belum pada edit data di database.
If Button2.Text = "EDIT" Then
Button2.Text = "SIMPAN"
Button1.Enabled = "false"
Button3.Enabled = "false"
Button4.Text = "BATAL"
TextBox1.Focus()
End If
c. Button3 = Hapus
Private Sub Button3_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles Button3.Click
Call bersih()
End Sub
Dimana telah dijelaskan sebelumnya tentang method bersih maka pada button ini hanya berisi pemanggilan method beersih untuk mengosongkan isi pada Textbox.
d. Button4 = Keluar
If Button4.Text = "KELUAR" Then
Me.Close()
Else
Call bersih()
Call normal()
End If
Pada button ini dijelaskan jika text pada button “Keluar” maka akan terjadi Me.close yaitu Form akan menutup dengan sendirinya atau keluar dari aplikasi, jika terhubung dengan form Menu maka akan kembali pada form Menu.
Untuk call normal buatlah terlebih dulu Sub pada Class yang sama sub normal dengan isi enable dari tiap – tiap button.
Sub normal()
Button1.Text = "SAVE"
Button1.Enabled = "true"
Button2.Text = "EDIT"
Button2.Enabled = "true"
Button3.Text = "HAPUS"
Button3.Enabled = "true"
Button4.Text = "KELUAR"
Button4.Enabled = "true"
Button5.Text = "FIND"
End Sub
e. Button5 = Find
Pada button ini penulis belum mengisi sintak dikarenakan materi yang belum mencukupi.
Nah Nie Coding utuhnya:
Public Class Data_Supplier
Dim item As ListViewItem
Dim isitext(3) As String
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
End Sub
Private Sub ListView1_ItemSelectionChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.ListViewItemSelectionChangedEventArgs) Handles ListView1.ItemSelectionChanged
TextBox4.Text = e.Item.Text
End Sub
Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
End Sub
Sub tampilan()
ListView1.View = View.Details
ListView1.Columns.Add("KD_SUPPLIER", 200, HorizontalAlignment.Left)
ListView1.Columns.Add("NM_SUPPLIER", 200, HorizontalAlignment.Left)
ListView1.Columns.Add("ALAMAT", 200, HorizontalAlignment.Left)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Button1.Text = "SAVE" Then
Button1.Text = "TAMBAH"
Button2.Enabled = "false"
Button3.Enabled = "false"
Button4.Text = "BATAL"
Button5.Text = "FIND"
TextBox1.Focus()
Else
isitext(0) = Trim(TextBox1.Text)
isitext(1) = Trim(TextBox2.Text)
isitext(2) = Trim(TextBox3.Text)
item = New ListViewItem(isitext)
ListView1.Items.Add(item)
Call bersih()
TextBox1.Focus()
End If
End Sub
Sub normal()
Button1.Text = "SAVE"
Button1.Enabled = "true"
Button2.Text = "EDIT"
Button2.Enabled = "true"
Button3.Text = "HAPUS"
Button3.Enabled = "true"
Button4.Text = "KELUAR"
Button4.Enabled = "true"
Button5.Text = "FIND"
End Sub
Sub bersih()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If Button4.Text = "KELUAR" Then
Me.Close()
Else
Call bersih()
Call normal()
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If Button2.Text = "EDIT" Then
Button2.Text = "SIMPAN"
Button1.Enabled = "false"
Button3.Enabled = "false"
Button4.Text = "BATAL"
TextBox1.Focus()
Else
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Call bersih()
End Sub
Private Sub Data_Supplier_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
Call bersih()
Call tampilan()
End Sub
End Class
List view untuk menampilkan data secara manual
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
ListBox1.Items.Clear()
ListBox2.Items.Clear()
ListBox3.Items.Clear()
For i = 2 To Val(TextBox1.Text)
ListBox1.Items.Add("*" + i.ToString + "," + (i + 1).ToString)
Next
For i = 1 To Val(TextBox1.Text)
If i Mod 4 Then
ListBox2.Items.Add(i)
End If
Next
For i = 1 To Val(TextBox1.Text)
If i Mod 3 = 2 Then
ListBox3.Items.Add(i)
End If
Next
End Sub
End Class
Dim i As Integer
ListBox1.Items.Clear()
ListBox2.Items.Clear()
ListBox3.Items.Clear()
For i = 2 To Val(TextBox1.Text)
ListBox1.Items.Add("*" + i.ToString + "," + (i + 1).ToString)
Next
For i = 1 To Val(TextBox1.Text)
If i Mod 4 Then
ListBox2.Items.Add(i)
End If
Next
For i = 1 To Val(TextBox1.Text)
If i Mod 3 = 2 Then
ListBox3.Items.Add(i)
End If
Next
End Sub
End Class
Langganan:
Postingan (Atom)