Kamis, 31 Maret 2011
latihan soal uts
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a, b, c, d, f, g, j As Integer
a = 7
b = 8
For f = Val(TextBox1.Text) To Val(TextBox2.Text)
If f Mod 3 = 0 Or f Mod 4 = 0 Or f Mod 7 = 0 Then
ListBox1.Items.Add(f)
Else
j = f
ListBox2.Items.Add(j)
End If
Next
For g = Val(TextBox1.Text) To Val(TextBox2.Text)
Next
For c = Val(TextBox1.Text) To Val(TextBox2.Text)
If c Mod a = 0 Then
d = c
ListBox3.Items.Add(d)
Else
If c Mod b = 0 Then
d = c
ListBox3.Items.Add(d)
End If
End If
Next
End Sub
Sub bersih()
TextBox1.Text = ""
TextBox2.Text = ""
ListBox1.Items.Clear()
ListBox2.Items.Clear()
ListBox3.Items.Clear()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Call bersih()
End Sub
End Class
materi2 tambahan 2
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
materi 2tambahan
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
materi 3
Public Class Form2
Dim listtxt(3) As String
Dim listitems As ListViewItem
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call setlistview()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
listtxt(0) = Trim(TextBox1.Text)
listtxt(1) = Trim(TextBox2.Text)
listtxt(2) = Trim(TextBox3.Text)
listitems = New ListViewItem(listtxt)
ListView1.Items.Add(listitems)
End Sub
Sub setlistview()
ListView1.View = View.Details
ListView1.Columns.Add("NPM", 100, HorizontalAlignment.Center)
ListView1.Columns.Add("Nama", 100, HorizontalAlignment.Left)
ListView1.Columns.Add("Alamat", 300, HorizontalAlignment.Left)
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
materi 2
Public Class Form1
Private Sub Label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label4.Click
End Sub
Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
Call bersih()
Call isicombo()
End Sub
Sub bersih()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
ComboBox1.Text = "06 Teknik Informatika"
End Sub
Sub isicombo()
ComboBox1.Items.Add("06 Teknik Informatika")
ComboBox1.Items.Add("07 Sistem Informasi")
ComboBox1.Items.Add("05 Management Informatika")
ComboBox1.Items.Add("67 Komputer Akutansi")
ComboBox1.Items.Add("26 teknik Komputer")
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 normal()
Call bersih()
End If
End Sub
Sub normal()
Button1.Text = "Tambah"
Button1.Enabled = True
Button2.Text = "Ubah"
Button2.Enabled = True
Button3.Text = "Hapus"
Button3.Enabled = True
Button4.Text = "Keluar"
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()
Else
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
materi 1
Public Class Form1
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
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
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
ListBox1.Items.Clear()
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 Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim a, b, c As Integer
b = 10
c = 12
For a = 10 To Val(TextBox2.Text)
If a Mod b = 0 Then
ListBox1.Items.Add(a)
b = a
Else
If a Mod c = 0 Then
ListBox1.Items.Add(a * -1)
c = a
End If
End If
Next
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim a, b, c As Integer
b = 9
c = 27
For a = 1 To Val(TextBox2.Text)
If a Mod b = 0 Then
If a Mod c = 0 Then
ListBox1.Items.Add(a)
c = a
End If
End If
Next
End Sub
End Class
Rabu, 09 Maret 2011
tugas vb 1
Dari soal di bawah ini dibuatkan program aplikasi dengan menggunakan vb
1. Menampilkan bilangan yang yang habis dibagi 9 dan 27
2. menampilkan bilangan yang sisa hasil baginya 3 dari pembagi 2
Dengan menggunakan Visual studio kita tuliskan coding sbb
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
For a = 1 To Val(TextBox1.Text)
If a Mod 9 = 0 And a Mod 27 = 0 Then
ListBox1.Items.Add(a)
End If
Next
End Sub
Private Sub Button1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Button1.KeyPress
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
For a = 1 To Val(TextBox1.Text)
If a Mod 2 = 3 Then
ListBox2.Items.Add(a)
End If
Next
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
End Class
dari coding diatas tampilanya sebagai berikut