Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 150,239 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 2,357 people online right now. Registration is fast and FREE... Join Now!




Find Prime number in specific range. Please help~~

 
Reply to this topicStart new topic

Find Prime number in specific range. Please help~~

jason7361
10 Nov, 2007 - 12:27 AM
Post #1

New D.I.C Head
*

Joined: 6 Oct, 2007
Posts: 8


My Contributions
I am writing a project to find prime number between specific range
here is the example:

IPB Image

i use some for loop to search the number
and it can show me which number is prime number or not
but i don't know how to put my prime number into the list
here is what i can get so far.
IPB Image

can anyone help me? Thanks a lot smile.gif
here are my code:

CODE

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim a As Double
        Dim b As Double
        Dim c As Double
        a = Val(TextBox1.Text)
        b = Val(TextBox2.Text)

        For a = a To b Step 1

            For c = 2 To a - 1 Step 1

                If a Mod c = 0 Then

                    Exit For

                End If

            Next
            ListBox1.Items.Addİ
        Next


    End Sub


can anyone tell me how to fix it?

This post has been edited by jayman9: 10 Nov, 2007 - 01:57 PM
User is offlineProfile CardPM
+Quote Post

Mr Ed
RE: Find Prime Number In Specific Range. Please Help~~
10 Nov, 2007 - 04:19 AM
Post #2

New D.I.C Head
*

Joined: 9 Nov, 2007
Posts: 14


My Contributions
CODE

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim a As Double
        Dim b As Double
        Dim c As Double
        a = Val(TextBox1.Text)
        b = Val(TextBox2.Text)

        For a = a To b Step 1
            For c = 2 To a - 1 Step 1
                If a Mod c = 0 Then
                    Exit For
                Else
                    ListBox1.Items.Add(a)
                    Exit For
                End If
            Next
        Next
    End Sub

QUOTE

can anyone tell me how to fix it?


Add the else and exit for


User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 06:18AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month