Need some help with VB (prime numbers and factors)

I am trying to get a VB program that will determine whether or not a user-generated number is prime or not. Right now, all I have is this:

Dim num As Integer
        Dim factor As Integer
        factor = 1
        num = TextBox1.Text
        Do While num >= factor
            If num Mod factor = 0 Then
                RichTextBox1.AppendText(vbCrLf & factor)
            End If
            factor = factor + 1

It's just getting the factors of a number. I cannot get it to tell prime numbers apart, however. Any help?
3 answers Last reply
More about need prime numbers factors
  1. Okay, after looking and and searching, I now have:

    Dim num As Integer
            Dim i As Integer
            Dim counter As Integer
            num = TextBox1.Text
            counter = 0
            i = 1
            Do While i <= num
                If num Mod i = 0 Then
                    counter = counter + 1
                End If
                i = i + 1
            If counter = 2 Then
                TextBox2.Text = "This is a prime number!"
                TextBox2.Text = "This is NOT a Prime number!"
            End If

    However, I don't know what the counter does exactly.. (part of this was copied)

    Could someone explain?
  2. Here is a hint, the defination of a prime number is a number that can be divided by one and itself. Go through the code line by line and see if you can't understand what it is doing.
  3. got it now. we actually just did stuff with it in class today.
Ask a new question

Read More

Programming Apps