VB.NET array and listboxes

5 pts.
Tags:
VB.NET
Revise the Sample Problem by reading ten (10) integer values and storing these values in an array. Determine and display the number of prime numbers entered.
What is the error in my code?
Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim MyArray(9), ctr As Integer
        Dim j, k As Integer
        For ctr = 0 To 9
            MyArray(ctr) = InputBox("Input number :")
            ListBox1.Items.Add(MyArray(ctr))
        Next
 
        For j = 2 To (MyArray(ctr) - 1)
            If MyArray(ctr) Mod j = 0 Then
                k = k + 1
            End If
        Next
        TextBox1.Text = k
    End Sub
End Class


Software/Hardware used:
Vb.net
1

Answer Wiki

Thanks. We'll let you know when a new response is added.
did not see any code on determining if it’s a prime number.
A quick Google search and you find this
Dim primeN As Integer
Dim primeI As Integer
Dim primeFlag As Boolean

primeN = Int32.Parse(Console.ReadLine())

primeFlag = True
For primeI = 2 To primeN / 2
    If primeN Mod primeI = 0 Then
        primeFlag = False
    End If
Next
If primeFlag Then
    Console.WriteLine("Is prime")
Else
    Console.WriteLine("Is not prime")
End If

Console.ReadLine()

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: