1 Replies - 4501 Views - Last Post: 10 November 2007 - 05:19 AM Rate Topic: -----

#1 jason7361  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 8
  • Joined: 07-October 07

Find Prime number in specific range. Please help~~

Post icon  Posted 10 November 2007 - 01:27 AM

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

Posted 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.
Posted Image

can anyone help me? Thanks a lot :)
here are my 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 November 2007 - 02:57 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Find Prime number in specific range. Please help~~

#2 Mr Ed  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 19
  • Joined: 09-November 07

Re: Find Prime number in specific range. Please help~~

Posted 10 November 2007 - 05:19 AM

	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
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1