| | |
Prime Number (Help Plz!)
Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Mar 2008
Posts: 7
Reputation:
Solved Threads: 0
i have to create application that ask user to input Lower bound and upper bound (both intger) greater than 1 and determins all of the prime numbers within the specified bounds, inclusive. and write function procedure prime that returns True if a number is prime. False otherwise. i also should use error provider.
i wrote these 2.. but both are not working ??
i don't know where is my mistake
any help plz ??
i have to submit my project tomorrow
i wrote these 2.. but both are not working ??
i don't know where is my mistake
any help plz ??
i have to submit my project tomorrow
•
•
•
•
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
Dim a As Integer
Dim b As Integer
ListBox1.Items.Add(Prime(Val(TextBox1.Text))
For i = a To b
ListBox1.Items.Add(i)
Next
End Sub
Function Prime(ByVal b As Integer) As Boolean
Dim i As Integer
Dim a As Integer
a = TextBox1.Text
b = TextBox2.Text
For i = a To b - 1
If b Mod a = 0 Then
Prime = False
Exit Function
End If
Next i
Prime = True
ListBox1.Items.Add(i)
Return a
End Function
End Class
•
•
•
•
Public Class Form1
Dim i As Integer
Dim n As Integer
Dim a As Integer
Dim b As Integer
Dim c As Integer
Private Sub btnCalP_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalP.Click
a = Val(txtLoBo.Text)
b = Val(txtUpBo.Text)
lstPN.Items.Add(Prime(Val(txtLoBo.Text), Val(txtUpBo.Text)))
For i = a To b
If b Mod 2 <> 0 Then
lstPN.Items.Add(c)
End If
Next
End Sub
Function Prime(ByVal a As Integer, ByVal b As Integer) As Integer
Dim flag As Boolean = True
If a Mod 2 <> 0 Then
For c = 2 To b - 1
If a Mod c = 0 Then
flag = False
Else
lstPN.Items.Add(c)
flag = True
End If
Next
end if
Return flag = True
Return flag = False
End Function
End Class
first you must know the type and patern of prime number :
Hope the following code is solved your problem :
Hope this helps.
don't forget to give feedback
Hope the following code is solved your problem :
vb.net Syntax (Toggle Plain Text)
Private Sub PrimeNumber(ByVal Low As Integer, ByVal Up As Integer) Dim i As Integer For i = Low To Up If (i = 2) Or (i = 3) Or (i = 5) Or (i = 7) Then ListPN.Items.Add(i) Else If (i Mod 2 <> 0) And (i Mod 3 <> 0) And (i Mod 5 <> 0) And (i Mod 7 <> 0) Then ListPN.Items.Add(i) End If End If Next End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ListPN.Items.Clear() PrimeNumber(txtLower.Text, txtUpper.Text) End Sub
Hope this helps.
don't forget to give feedback
Last edited by Jx_Man; Mar 11th, 2008 at 5:25 am.
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
So, Please do something before post your thread.
* PM Asking will be ignored *
you're welcome 
don't forget to mark this thread solved

don't forget to mark this thread solved
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
So, Please do something before post your thread.
* PM Asking will be ignored *
•
•
Join Date: Mar 2008
Posts: 7
Reputation:
Solved Threads: 0
Last edited by miss.A; Mar 12th, 2008 at 7:06 am.
i have tried it. and i don't get result 200.just between 1-199.
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
So, Please do something before post your thread.
* PM Asking will be ignored *
![]() |
Similar Threads
- prime number question (C)
- plz help! (C++)
- Urgent: Plz Help me,Prime Number Program Problem (C++)
- C++ prime number program help (C++)
- Finding Perfect Numbers. "help plz" (C++)
- a beginner needs help (C++)
Other Threads in the VB.NET Forum
- Previous Thread: hiiiiiiii
- Next Thread: Web browser with predermined par of URL
| Thread Tools | Search this Thread |
"crystal .net .net2005 30minutes 2008 access add application array assignment basic binary box button buttons center click code combo connectionstring convert cpu data database databasesearch datagrid datagridview design dissertation dissertations dissertationthesis dosconsolevb.net editvb.net employees excel exists firewall folder function image images isnumericfuntioncall listview login math memory mobile module msaccess mssqlbackend mysql navigate net opacity page pan peertopeervideostreaming picturebox plugin port print printing printpreview record regex reports" reuse right-to-left save savedialog search serial socket sorting sql sqldatbase storedprocedure string structures studio temp textbox timer txttoxmlconverter upload useraccounts usercontol usercontrol vb vb.net vb.netcode vb.nettoolboxvisualbasic2008sidebar vbnet vista visual visualbasic visualbasic.net web wpf xml






