Minggu, 11 November 2012

TUGAS 4


MEMBUAT PROGRAM CHECKBOX
·         Pertama tama buka Microsoft Visual Studio .
·         Lalu buat 6 buah checkbox ,pilih menu toolbar dan pilih checkbox .
·         Namai semua checkbox dengan nama Indonesia ,Inggris ,Sunda ,Jawa dan lain-lain .
·         Lalu pilih menu toolbox pilih groupbox pasangkan pada checkbox .
·         Berikut coding dari checkbox :

Public Class Form1
    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

    Private Sub CheckBox7_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox7.CheckedChanged
        Dim control As Windows.Forms.CheckBox
        TextBox1.Text = ""
    End Sub

    Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox1.Enter

    End Sub
End Class

·         Berikutnya piloh menu toolbar lagi dan pilih textbox .
·         Berikut codingan untuk textbox :

Public Class Form1
    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

    Private Sub CheckBox7_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox7.CheckedChanged
        Dim control As Windows.Forms.CheckBox
        TextBox1.Text = ""
    End Sub

    Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox1.Enter

    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

    End Sub
End Class

·         Langkah berikutnya pilih menu toolbar lagi dan pilih button & beri nama “Proces”
·         Berikut coding dari button :

Public Class Form1
    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

    Private Sub CheckBox7_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox7.CheckedChanged
        Dim control As Windows.Forms.CheckBox
        TextBox1.Text = ""
    End Sub

    Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox1.Enter

    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

    End Sub
End Class




·         Selesai mulai run program & jalankan !


MEMBUAT PROGRAM FIBONACI

·         Buka Microsoft visual studio
·         Pilih menu toolbar pilih label ,beri nama “Bilangan Fibonaci”
·         Pilih menu toolbox lagi dan pilih textbook .
·         Berikut coding dari textbox :


Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim fibo(19) As Integer
        Dim ulang As Integer
        fibo(0) = 1
        fibo(1) = 1
        For ulang = 2 To 19
            fibo(ulang) = fibo(ulang - 2) + fibo(ulang - 1)
        Next
        For ulang = 0 To 19
            ListBox1.Items.Add(fibo(ulang))
        Next
    End Sub

    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged

    End Sub
End Class

·         Buat button dan beri nama “Proces”
·         Berikut coding dari button :

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim fibo(19) As Integer
        Dim ulang As Integer
        fibo(0) = 1
        fibo(1) = 1
        For ulang = 2 To 19
            fibo(ulang) = fibo(ulang - 2) + fibo(ulang - 1)
        Next
        For ulang = 0 To 19
            ListBox1.Items.Add(fibo(ulang))
        Next
    End Sub

    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged

    End Sub
End Class




·         Selesai tinggal di run & jalankan program !

LATIHAN MEMBUAT LISTBOX

·         Buat label dengan codingan seperti berikut :

Public Class Form1
    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 Bt_Satu.Click
        ListBox1.Text = ListBox2.Items.Add(ListBox1.Text)
    End Sub
    Private Sub Bt_Beberapa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt_Beberapa.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 Bt_Semua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt_Semua.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 Bt_Hapus_Satu.Click
        ListBox2.SelectionMode = SelectionMode.One

        ListBox2.Items.Remove(ListBox2.SelectedItem)
    End Sub
    Private Sub Bt_Hapus_Beberapa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt_Hapus_Beberapa.Click
        ListBox2.SelectionMode = SelectionMode.MultiExtended
        Dim i, j As Integer
        j = ListBox2.Items.Count


        For i = 0 To j - 1
            Try
                ListBox2.Items.RemoveAt(ListBox2.SelectedIndex)
            Catch ex As Exception
                j -= 1
            End Try
        Next
    End Sub
    Private Sub Bt_Hapus_Semua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt_Hapus_Semua.Click
        ListBox2.Items.Clear()
    End Sub
    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        Me.Close()
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

    End Sub
End Class

·         Buat 9 tombol buuton dengan nama “ isi,1-10,satu,beberap,semua,hapus satu,hapus beberapa,hapus semua ,tutup.
·         Coding seperti berikut
·         Dan buat textbox 2 buah .

Public Class Form1
    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 Bt_Satu.Click
        ListBox1.Text = ListBox2.Items.Add(ListBox1.Text)
    End Sub
    Private Sub Bt_Beberapa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt_Beberapa.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 Bt_Semua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt_Semua.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 Bt_Hapus_Satu.Click
        ListBox2.SelectionMode = SelectionMode.One

        ListBox2.Items.Remove(ListBox2.SelectedItem)
    End Sub
    Private Sub Bt_Hapus_Beberapa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt_Hapus_Beberapa.Click
        ListBox2.SelectionMode = SelectionMode.MultiExtended
        Dim i, j As Integer
        j = ListBox2.Items.Count


        For i = 0 To j - 1
            Try
                ListBox2.Items.RemoveAt(ListBox2.SelectedIndex)
            Catch ex As Exception
                j -= 1
            End Try
        Next
    End Sub
    Private Sub Bt_Hapus_Semua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt_Hapus_Semua.Click
        ListBox2.Items.Clear()
    End Sub
    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        Me.Close()
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

    End Sub
End C






MEMBUAT CHECKBOX

·         Buat 3 label dengan nama “jenis kelamin ,status ,pasangan hidup “
·         4 buah checkbox dengan nama “pria,wanita,kawin,belum kawin”
·         1 text box
·         1 label dengan nama “tutup”
·         Berikut codingan dari program checkbox !

Public Class Form1

    Private Sub RbKawin_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RbKawin.CheckedChanged
        TextBox1.Text = ""
        If RbPria.Checked = True Then
        Else
            TextBox1.Text &= "Istri"
        End If
        If RbWanita.Checked = True Then
        Else
            TextBox1.Text &= "Suami"
        End If
    End Sub
  
    Private Sub RbTdkwin_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RbTdkwin.CheckedChanged
        TextBox1.Text = ""
        If RbPria.Checked = True Then
        Else
            TextBox1.Text &= ""
        End If
        If RbWanita.Checked = True Then
        Else
            TextBox1.Text &= ""
        End If
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.Close()
    End Sub

    Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click

    End Sub
End Class