Kamis, 31 Maret 2011

Contoh VB4

Contoh VB4


Scrip
Public Class Form1
'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
' Masukkan nilai ke variable aray'
listtxt(0) = Trim(TextBox1.Text)
listtxt(1) = Trim(TextBox2.Text)
listtxt(2) = Trim(TextBox3.Text)

'Untuk memasukkan ke listview dari variable'
listitem = New ListViewItem(listtxt)
ListView1.items.Add(listitem)
End Sub
'Setting Kolom list view
Sub setlistview()

ListView1.View = View.Details

'Untuk menampilkan kolom
ListView1.Columns.Add("NPM", 100, HorizontalAlignment.Center)
ListView1.Columns.Add("Nama", 100, HorizontalAlignment.Left)
ListView1.Columns.Add("Alamat", 100, HorizontalAlignment.Right)
End Sub


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call setlistview()
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
End Class

Contoh VB3

Contoh VB3


Scrip
Public Class Form3
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles proses.Click
For i = 1 To Val(TextBox1.Text)
If i Mod 9 = 0 And i Mod 27 = 0 Then
ListBox1.Items.Add(i)
End If
Next

For i = 1 To Val(TextBox1.Text)
If i Mod 2 = 3 Then
ListBox3.Items.Add(i)
End If
Next

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
proses.Focus()
End If

End Sub

Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click

End Sub
End Class

Contoh VB2

Contoh VB2


Scrip
Public Class Form2

Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
If e.KeyChar = Chr(13) Then
Button1.Focus()
End If
End Sub



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
For i = 5 To Val(TextBox2.Text)
If (i Mod 2 = 0) Then
ListBox1.Items.Add(i * -1)

Else
ListBox1.Items.Add(i)

End If
Next

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
ComboBox1.Items.Add(TextBox1.Text)
End If
End Sub
End Class

Lat. VB1

Lat. VB1


Scrip
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

If TextBox1.Text = "TI" Then
TextBox2.Text = "teknik informatika"
Else
If TextBox1.Text = "SI" Then
TextBox2.Text = "sistem informasi"
End If
End If
End Sub


Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
ListBox1.Items.Add(TextBox3.Text + " " + TextBox4.Text + " " + TextBox5.Text + " " + TextBox6.Text + " " + TextBox7.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
TextBox4.Focus()
End If
End Sub

Private Sub TextBox4_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox4.KeyPress
If e.KeyChar = Chr(13) Then
TextBox5.Focus()
End If
End Sub

Private Sub TextBox5_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox5.KeyPress
If e.KeyChar = Chr(13) Then
TextBox6.Focus()
End If
End Sub

Private Sub TextBox6_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox6.KeyPress
If e.KeyChar = Chr(13) Then
TextBox7.Focus()
End If
End Sub

Private Sub TextBox7_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox7.KeyPress
If e.KeyChar = Chr(13) Then
ListBox1.Items.Add(TextBox3.Text + " " + TextBox4.Text + " " + TextBox5.Text + " " + TextBox6.Text + " " + TextBox7.Text)
Call bersih()
End If
End Sub

Sub bersih()
TextBox3.text = ""
TextBox4.text = ""
TextBox5.text = ""
TextBox6.text = ""
TextBox7.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
Button1.Focus()
End If
End Sub
End Class

Latihan VB pertemuan ke 6

Pertemuan ke 6


Scrip
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
End Class

Semua yang telah berpatisipasi saya ucapkan
Thank you so much