Nama-nama objek yang digunakan :
1. Listbox1
2. Textbox1
3. Button1
4. Button2
5. Combobox1
6. Textboxb2
CODING :
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
ListBox1.Items.Clear()
Dim i As Byte
For i = 1 To 5
ListBox1.Items.Add(i)
Next
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
ComboBox1.Items.Clear()
Dim a As Byte
Do While a < 5 a = a + 1 ComboBox1.Items.Add(a) Loop End Sub Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged If ListBox1.Text = "1" Then TextBox1.Text = "Satu" ElseIf ListBox1.Text = "2" Then TextBox1.Text = "dua" ElseIf ListBox1.Text = "3" Then TextBox1.Text = "tiga" ElseIf ListBox1.Text = "4" Then TextBox1.Text = "empat" ElseIf ListBox1.Text = "5" Then TextBox1.Text = "lima" End If End Sub Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged Select Case ComboBox1.Text Case 1 TextBox2.Text = 1000 Case 2 TextBox2.Text = 2000 Case 3 TextBox2.Text = 3000 Case 4 TextBox2.Text = 4000 Case 5 TextBox2.Text = 5000
End Select
End Sub
End Class
Contoh program Kelas dan Jurusan Coding : Public Class KelasJurusan Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click TextBox1.Clear() TextBox2.Clear() TextBox3.Clear() TextBox1.Focus() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click End 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 If TextBox1.Text = "" Then MsgBox("Nama harus diisi") TextBox1.Focus() Exit Sub Else TextBox2.Focus() End If 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 If TextBox2.Text = "" Then MsgBox("Kelas harus diisi") www.krisnasoft.com Modul VB.Net 2005 Hal - 4 – Else TextBox2.Focus() Exit Sub If TextBox2.Text <> "MI" And TextBox2.Text <> "MA" And
TextBox2.Text <> "SK" And TextBox2.Text <> "AK" Then
MsgBox("Kelas tidak terdaftar")
TextBox2.Focus()
Else
If TextBox2.Text = "MI" Then TextBox3.Text =
"Manajemen Informatika"
If TextBox2.Text = "MA" Then TextBox3.Text =
"Manajemen Adminsitrasi"
If TextBox2.Text = "SK" Then TextBox3.Text =
"Sekretari"
"Akuntansi"
If TextBox2.Text = "AK" Then TextBox3.Text =
Button1.Focus()
End If
End If
End If
End Sub
End Class
Tidak ada komentar:
Posting Komentar