Tugas 4
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim control As Windows.Forms.ListBox
TextBox1.Text = TextBox1.Text
TextBox1.Text = ListBox1.Items.Add(TextBox1.Text)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
For bil = 1 To 10
ListBox1.Items.Add(bil)
Next
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
ListBox1.Text = ListBox2.Items.Add(ListBox1.Text)
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
ListBox1.SelectionMode = SelectionMode.MultiExtended
Dim i, j As Integer
j = ListBox1.Items.Count
For i = 0 To j - 1
Try
ListBox2.Items.Add(ListBox1.Items(ListBox1.SelectedIndices(i)))
Catch ex As Exception
j -= 1
End Try
Next
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
ListBox1.SelectionMode = SelectionMode.MultiExtended
Dim Jumlah As Integer = ListBox1.Items.Count
For i = 0 To Jumlah - 1
ListBox2.Items.Add(ListBox1.Items(i))
Next
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
ListBox2.SelectionMode = SelectionMode.One
ListBox2.Items.Remove(ListBox2.SelectedItem)
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
ListBox2.SelectionMode = SelectionMode.MultiExtended
Dim a, b As Integer
b = ListBox2.Items.Count
For a = 0 To b - 1
Try
ListBox2.Items.RemoveAt(ListBox2.SelectedIndex)
Catch ex As Exception
b -= 1
End Try
Next
End Sub
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
ListBox2.Items.Clear()
End Sub
End Class
2.Radio Button
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If RadioButton1.Checked = True And RadioButton3.Checked = True Then
TextBox1.Text = "ISTRI"
ElseIf RadioButton2.Checked = True And RadioButton3.Checked = True Then
TextBox1.Text = "SUAMI"
ElseIf RadioButton1.Checked = True Or RadioButton2.Checked = True And RadioButton4.Checked = True Then
TextBox1.Text = "JOMBLO"
End If
End Sub
3.Fibonacci
Private Sub Bttampilkan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bttampilkan.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
4.Prima
Dim bilangan(100) As String
Dim x, y As Integer
For x = 2 To 100
If bilangan(x) <> " * " Then
ListBox1.Items.Add(x)
For y = 2 * x To 100 Step x
bilangan(y) = " * "
Next
End If
Next
End Sub
5.Check Box
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
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
TextBox1.Text = Microsoft.VisualBasic.Left(TextBox1.Text, Len(TextBox1.Text) - 1)
End Sub
Komentar
Posting Komentar