Write a Vb.net program to design the following form, accept the numbers through textbox and add them into the ListBoxe1 by clicking on Add button. When user click on Prime button then all the prime numbers from ListBox1 should get added into ListBox2.

 Form:-


Program:-

Public Class slip12    

        ' Add button

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

        ListBox1.Items.Add(CInt(TextBox1.Text))

        TextBox1.Text = ""

        TextBox1.Focus()

    End Sub

    ' Prime Button

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

        Dim n, i, mm, count, contain As Integer


        For i = 0 To ListBox1.Items.Count() - 1

            n = ListBox1.Items.Item(i)

            count = CInt(n) / 2

            mm = 1

            For j As Integer = 2 To count

                If n Mod j = 0 Then

                    mm = 0

                End If

            Next

            If mm = 1 Then

                ListBox2.Items.Add(CInt(n))

            End If

        Next


        contain = ListBox1.Items.Count() - 1 ' 4

        i = 0



        While True

            If contain >= i Then

                n = ListBox1.Items.Item(i)

                count = CInt(n) / 2

                mm = 1

                For j As Integer = 2 To count

                    If n Mod j = 0 Then

                        mm = 0

                    End If

                Next

                If mm = 1 Then

                    ListBox1.Items.RemoveAt(i)

                Else

                    i = i + 1

                End If

                contain = ListBox1.Items.Count() - 1

            Else

                Exit While

            End If

        End While

    End Sub

End Class


Output:-


Design:-

1) Take a Label, Textbox, 2 Listboxes, 2 Buttons on design form.

2) Set text on labels and buttons.


Note - Set startup form's application type as Windows Form Application



0 Comments