TEST VISUAL BASIC 1
Public Class Form1
Dim isitex(4) As String
Dim Item As ListViewItem
Sub isi()
ComboBox1.Items.Add("Teknik Informatika")
ComboBox1.Items.Add("Sistem Informatika")
ComboBox1.Items.Add("Komputer akutansi")
ComboBox1.Items.Add("Manajemen Informatika")
ComboBox1.Items.Add("Teknik Komputer")
End Sub
Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
Call isi()
Call Tabel()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Call hapus()
End Sub
Sub hapus()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
ComboBox1.Text = "Teknik Informatika"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Button1.Text = "Tambah" Then
Button1.Text = "Simpan"
Button2.Enabled = False
Button3.Enabled = False
Button4.Text = "Batal"
TextBox1.Focus()
ElseIf Button1.Text = "Simpan" Then
isitex(0) = Trim(TextBox1.Text)
isitex(1) = Trim(TextBox2.Text)
isitex(2) = Trim(TextBox3.Text)
isitex(3) = Microsoft.VisualBasic.Left(Trim(ComboBox1.Text), 100)
Item = New ListViewItem(isitex)
ListView1.Items.Add(Item)
End If
Button1.Focus()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If Button4.Text = "Batal" Then
Button1.Text = "Tambah"
Button1.Enabled = True
Button2.Text = "Edit"
Button2.Enabled = True
Button3.Text = "Hapus"
Button3.Enabled = True
Button4.Text = "Keluar"
TextBox1.Focus()
Else
Button4.Text = "Keluar"
Me.Close()
End If
End Sub
Sub Tabel()
ListView1.View = View.Details
ListView1.Columns.Add("NPM", 100, HorizontalAlignment.Center)
ListView1.Columns.Add("Nama", 100, HorizontalAlignment.Left)
ListView1.Columns.Add("Alamat", 100, HorizontalAlignment.Left)
ListView1.Columns.Add("Jurusan", 100, HorizontalAlignment.Left)
End Sub
Private Sub ListView1_ItemSelectionChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.ListViewItemSelectionChangedEventArgs) Handles ListView1.ItemSelectionChanged
TextBox1.Text = e.Item.Text
End Sub
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = Chr(13) Then
TextBox2.Focus()
End If
End Sub
Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
If e.KeyChar = Chr(13) Then
TextBox3.Focus()
End If
End Sub
Private Sub TextBox3_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox3.KeyPress
If e.KeyChar = Chr(13) Then
ComboBox1.Focus()
End If
End Sub
Private Sub ComboBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ComboBox1.KeyPress
If e.KeyChar = Chr(13) Then
Button1.Focus()
End If
End Sub
Private Sub Button1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Button1.KeyPress
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
GAMBAR 1
LATIHAN TEST 2
Public Class Form2
'membuat variable array
Dim listtxt(3) As String
Dim listitem As ListViewItem
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'memasukan nilai ke varible array
listtxt(0) = Trim(TextBox1.Text)
listtxt(1) = Trim(TextBox2.Text)
listtxt(2) = Trim(TextBox3.Text)
'untuk memasukan ke listview dari variable array
listitem = New ListViewItem(listtxt)
ListView1.Items.Add(listitem)
End Sub
'setting kolom listview
Sub setlistview()
ListView1.View = View.Details
'untuk menentukan kolom
ListView1.Columns.Add("NPM", 100, HorizontalAlignment.Center)
ListView1.Columns.Add("Nama", 200, HorizontalAlignment.Left)
ListView1.Columns.Add("Alamat", 400, HorizontalAlignment.Left)
End Sub
Private Sub ListView1_ItemSelectionChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.ListViewItemSelectionChangedEventArgs) Handles ListView1.ItemSelectionChanged
'mengambil nilai dari listview
TextBox4.Text = e.Item.Text
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call setlistview()
End Sub
End Class
GAMBAR
LATIHAN TEST VB 3
Buat bilangan yang tidak habis dibagi 7 tetapi habis dibagi 3 di listbox 1 dan bilangan yang digit belakangnya angka 3 di listbox 2.......
Public Class Form2
'membuat variable array
Dim listtxt(3) As String
Dim listitem As ListViewItem
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'memasukan nilai ke varible array
listtxt(0) = Trim(TextBox1.Text)
listtxt(1) = Trim(TextBox2.Text)
listtxt(2) = Trim(TextBox3.Text)
'untuk memasukan ke listview dari variable array
listitem = New ListViewItem(listtxt)
ListView1.Items.Add(listitem)
End Sub
'setting kolom listview
Sub setlistview()
ListView1.View = View.Details
'untuk menentukan kolom
ListView1.Columns.Add("NPM", 100, HorizontalAlignment.Center)
ListView1.Columns.Add("Nama", 200, HorizontalAlignment.Left)
ListView1.Columns.Add("Alamat", 400, HorizontalAlignment.Left)
End Sub
Private Sub ListView1_ItemSelectionChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.ListViewItemSelectionChangedEventArgs) Handles ListView1.ItemSelectionChanged
'mengambil nilai dari listview
TextBox4.Text = e.Item.Text
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call setlistview()
End Sub
End Class
Gambar 1
LATIHAN TEST 4
Ø PENGABUNGAN DARI BEBERAPA KATA.....
Public Class Form2
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = Chr(13) Then
TextBox2.Focus()
End If
End Sub
Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
If e.KeyChar = Chr(13) Then
TextBox3.Focus()
End If
End Sub
Sub gabung()
ListBox1.Items.Add(Trim(TextBox1.Text) & " " & Trim(TextBox2.Text) & " " & Trim(TextBox3.Text))
End Sub
Private Sub TextBox3_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox3.KeyPress
If e.KeyChar = Chr(13) Then
TextBox2.Focus()
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call gabung()
End Sub
End Class
GAMBAR 1
Tidak ada komentar:
Posting Komentar