1.
Latihan 1 Bilangan Fibonacci
-
Codingnya :
Private Sub Button1_Click(ByVal sender As
System.Object, ByVal
e As System.EventArgs)
Handles Button1.Click
Dim bil As Integer
Dim fibonaci(10) As Integer
fibonaci(0) = 1
fibonaci(1) = 1
For bil = 2 To 9
fibonaci(bil) =
fibonaci(bil - 1) + fibonaci(bil - 2)
Next
For bil = 0 To 9
ListBox1.Items.Add(fibonaci(bil))
Next
End
Sub
Private
Sub Button2_Click(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles
Button2.Click
Me.Close()
End
Sub
End Class
2.
Latihan 2 Bilangan Prima
-
Codingnya :
Private Sub Button1_Click(ByVal sender As
System.Object, ByVal
e As System.EventArgs)
Handles Button1.Click
Dim tanda(100) As String
Dim x, y As Integer
For x = 2 To 100
If tanda(x) <> "*"
Then
ListBox1.Items.Add(x)
For y = 2 * x To 100 Step x
tanda(y) = "*"
Next
End If
Next
End
Sub
Private
Sub Button2_Click(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles
Button2.Click
Me.Close()
End
Sub
End Class
3.
Latihan 3 Pemilihan Bahasa
-
Codingnya :
Dim control As Windows.Forms.CheckBox
TextBox1.Text = ""
For Each control In Me.GroupBox1.Controls
If
control.Checked = True Then
TextBox1.Text &=
control.Text & ","
End
If
Next
End Sub
4.
Latihan 4 Radio Button
-
Codingnya :
Private Sub
Btproses_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles
Btproses.Click
If
RbKawin.Checked = True Then
If
RbPria.Checked = True Then
Munculkan.Text = "Istri"
Else
RbWanita.Checked = True
Munculkan.Text = "Suami"
End
If
Else
Munculkan.Text = ""
End If
End Sub
Private Sub Bttutup_Click(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles
Bttutup.Click
Me.Close()
End Sub
5.
Latihan 5 Listbox
-
Codingnya :
Public Class
Form1
Private Sub Btisis_Click(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles
Btisi.Click
ListBox1.Items.Add(TextBox1.Text)
TextBox1.Text = ""
TextBox1.Focus()
End Sub
Private Sub Btangka_Click(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles
Btangka.Click
Dim
angka As Integer
For
angka = 1 To 10
ListBox1.Items.Add(angka)
Next
End Sub
Private Sub BtSatu_Click(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles
BtSatu.Click
ListBox2.Items.Add(ListBox1.SelectedItem)
End Sub
Private Sub BtBeberapa_Click(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles
BtBeberapa.Click
Dim
beberapa = (From i In
ListBox1.SelectedItems).ToArray()
For Each
SelectedItems In beberapa
ListBox2.Items.Add(SelectedItems)
Next
End Sub
Private Sub BtSemua_Click(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles
BtSemua.Click
Dim
semua = (From i In
ListBox1.Items).ToArray()
For Each Items In semua
ListBox2.Items.Add(Items)
Next
End Sub
Private Sub BtHapus_Click(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles
BtHapus.Click
ListBox2.Items.Remove(ListBox2.SelectedItem)
End Sub
Private Sub BtHapusBeberapa_Click(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles
BtHapusBeberapa.Click
Dim
dipilih = (From i In
ListBox2.SelectedItems).ToArray()
For Each SelectedItems In
dipilih
ListBox2.Items.Remove(SelectedItems)
Next
End Sub
Private Sub BtHapusSemua_Click(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles
BtHapusSemua.Click
ListBox1.Items.Clear()
ListBox2.Items.Clear()
End Sub
Private Sub BtTutup_Click(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles
BtTutup.Click
Me.Close()
End Sub