Kamis, 09 Juni 2011

Menambahkan item ke combo box dari text box



Menambahkan item ke combo box dari text box
ada beberapa cara yang bisa dilakukan. namun cara yang umum adalah seperti berikut :



Menambahkan item ke combo box dari text box
ada beberapa cara yang bisa dilakukan. namun cara yang umum adalah seperti berikut :

Public Class Form1

Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

ComboBox1.Items.Add(TextBox1.Text)
End Sub
End Class

cara umum ini akan menambahkan inputan ke dalam combo box secara berurutan. penambahan dapat ditentukan sesuai keinginan baik dilakukan di paling atas, paling bawah, atau di index yang diinginkan dengan cara :
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
ComboBox1.Items.Insert(index ke berapa, TextBox1.Text)
End Sub

Belajar Logika
belajar logika yang dilakukan adalah dengan membuat program yang menghasilkan urutan bilangan sesuai yang diberikan oleh dosen
contoh
Buat deret bilangan berikut
-1,2,-3,4,-5

Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
For i = 1 To 5
If i Mod 2 = 1 Then
Dim a As Integer a = i * -1 ComboBox1.Items.Add(a)
Else
ComboBox1.Items.Add(i)
End If
Next
End Sub

dapat pula dengan cara berikut

Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
For i = 1 To 5
If i Mod 2 = 1 Then
ComboBox1.Items.Add(i * -1)
Else
ComboBox1.Items.Add(i)
End If
Next
End Sub

Sabtu, 26 Maret 2011

Hitung





Public Class Form1

Private Sub ListBox3_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox3.SelectedIndexChanged

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a, b As Integer
For a = 2 To 6
ListBox1.Items.Add("*" & a)
ListBox1.Items.Add(a + 1)
Next
For b = 1 To Val(TextBox1.Text)
If b Mod 4 <> 0 Then
ListBox2.Items.Add(b)
End If
If b Mod 3 = 2 Then
ListBox3.Items.Add(b)
End If
Next
End Sub
End Class

Selasa, 22 Maret 2011

Puzzle Vb.Net


Contohnya :

Public Class Form1
    Dim d As Integer = 0
    Dim a As Button
    Dim b As Point
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If d = 0 Then
            b = Button1.Location
            d = 1
            a = Button1
        Else
            a.Location = Button1.Location
            Button1.Location = b
            d = 0
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If d = 0 Then
            b = Button2.Location
            d = 1
            a = Button2
        Else
            a.Location = Button2.Location
            Button2.Location = b
            d = 0
        End If
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If d = 0 Then
            b = Button3.Location
            d = 1
            a = Button3
        Else
            a.Location = Button3.Location
            Button3.Location = b
            d = 0
        End If
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        If d = 0 Then
            b = Button4.Location
            d = 1
            a = Button4
        Else
            a.Location = Button4.Location
            Button4.Location = b
            d = 0
        End If
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        If d = 0 Then
            b = Button5.Location
            d = 1
            a = Button5
        Else
            a.Location = Button5.Location
            Button5.Location = b
            d = 0
        End If
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        If d = 0 Then
            b = Button6.Location
            d = 1
            a = Button6
        Else
            a.Location = Button6.Location
            Button6.Location = b
            d = 0
        End If
    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        If d = 0 Then
            b = Button7.Location
            d = 1
            a = Button7
        Else
            a.Location = Button7.Location
            Button7.Location = b
            d = 0
        End If
    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        If d = 0 Then
            b = Button8.Location
            d = 1
            a = Button8
        Else
            a.Location = Button8.Location
            Button8.Location = b
            d = 0
        End If
    End Sub

    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        If d = 0 Then
            b = Button9.Location
            d = 1
            a = Button9
        Else
            a.Location = Button9.Location
            Button9.Location = b
            d = 0
        End If
    End Sub
End Class