Write a program that asks a user to enter a number (number can be negative, positive, or zero), and then displays all prime numbers from zero to this number (for this project prime numbers can be positive and negative), and the product of all these prime number (must specify how many prime numbers are in the product)
The program must check for incorrect input, and have an EXIT button.
The form will have one text box, one button, and one list box.
I can not figure out the formula for prime numbers.
Any help will be greatly appreciated
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
I am working on a program for prime numbers and thus far i have
Dim Variable As String
Dim x As Integer
Private Sub txtInput_KeyPress(KeyASCII As Integer)
If KeyASCII = 13 Then
Total As Integer
Total = txtNum.Text
For x = 1 To Total
Do Until x = txtNum.Text
strVariable = txtNum.Text Mod x
If strVariable = 0 Then
Total = Total + x
x = x + 1
If Total = txtNum.Text + 1 Then
Else Total =
1. i am not sure if that is all write,
2. what goes after the last Else
Anyone know where i can find a programm for Visual Basic to find prime numbers
I have a question. Can someone help me make a program that finds all prime numbers from one value to another for example 1 to 100 and print them on the form. I know how to write the basis of it in basic and i was just wondering on how to do it visual basic. the reason i want to do this is because i saw it on a poster and it would probably broaden my skills. I am thinking that you have to use a array but i am not sure. Thanks
I have just added a feature to a prime number finder that lets users pick which number to start at (instead of 1). How can I tell VB to change the value of STEP from 2 to 1? How can I incorperate it into an If statement?
If x = odd number then...
I need some help, i found a part of this code, the rest i programmed, but i can't understand some parts, someone want to explain the sentences?
Other question, the listbox has got a limit? This question is because in winxp i can put all the numbers that i want to put, but in win98 i can't put it, and it says: error nº5.
Thanx, and sorry for my english.
Public Function EsPrimo(numero As Variant) As Boolean
If numero Mod 2 = 0 Then 'I don't it
EsPrimo = False
Dim i As Variant
Dim Primo As Boolean
numero = Abs(numero)
Primo = True
For i = 3 To CInt(Sqr(numero) + 1) Step 2 'I don't it
If numero Mod i = 0 Then
Primo = False
EsPrimo = Primo
Can anybody tell me how to locate prime numbers in a array of 10 random numbers.
I wrote this briefly in Visual Basic because I was bored and I thought it would be kinda cool. It calculates prime numbers from 1 to whatever. The highest ive gotten to go to is 1000. Someone with a faster computer might be able to get to some very big prime numbers.
All you need is a Text box called txtOutput that has its multiline propertie set to true and scrollbars propertie set to 2 - vertical and a Command Button called cmdPrime.
Private Sub cmdPrime_Click() Dim Number1 As Double, Number2 As Double, Number3 As Double, Check As Double, Prime As Boolean Prime = Prime For Number1 = 1 To 1000 If Prime Then For Number2 = 1 To Number1 If Prime Then For Number3 = 1 To Number1 Check = Number2 * Number3 If Check = Number1 And Number2 <> 1 And Number3 <> 1 Then Prime = False End If Next Number3 End If Next Number2 If Prime Then txtOutput.Text = txtOutput.Text & vbNewLine & Number1 End If End If Prime = True Next Number1End Sub
To change how high the calculations go, change the first For...Next loop number to 1 to whatever value u want.
Warning: Large numbers will take a long time.
Edit: Prime Numbers 1 to 2000 are as follows:
Hey.. I'm a newb so, as practice, I'm trying to create a function that determines if a number is prime or not. I thought maybe divide the number by every number inbetween 1 and itself and if the answer is a whole number, then it's not prime?
here's what I've tried so far...
Public Function PrimeNumber(Number As Long) As Boolean
For i = 2 To UserInput
Answer = UserInput / i
If Answer = Then
PrimeNumber = True
Else PrimeNumber = False
I wanna say If Answer = WholeNumber, dont know how...
How do you test for prime numbers? Example, it would be nice if I could go if Isprime(x) then ... Any help?
What would be the fastest way of finding primes numbers. I was able to find 10 million of them in 4762 secs on a p3-866 on win98.
I'm currently in a VB class at my high school. And the project that we are working on now is finding prime numbers. We must first start out with prime numbers that a less then 100, once we have found out how to do that we move on to 1,000... 10,000 and so on. Then we'll time our project and compare them to see who's program can find primes the fastest. What i am asking for is help on writing some code for this project. Hints, tips or if anyone wants bo be kind enough to tell me how to do the whole thing, that would be great. Thank You, Sincerely, doublej
Prime Numbers - Using A Function
I'm a newbie to VB and I have an assignment as follows.. User enters a low bound (number) and then a high bound - and a Function called Prime must return true or false, and then display all prime numbers between the two bounds in a textbox. Example between 2 and 20 - the following must be displayed in the textbox 2, 3, 5, 7, 11, 13, 17, 19.....
I just learned about Functions, but I have NO idea how to make VB determine prime... any idea's?
Finding Prime Numbers
hi everybody, was just wondering how to find the prime numbers between 2 input numbers. The person would type the minimum number and the maximum number in text boxes, then the program would return all the prime numbers between the two input numbers. I can't figure out how to find the prime numbers, can anyone help me?
thanks in advance
Prime Numbers Problema
I´m trying to write a PUBLIC SUB procedure that calculates and prints the N first prime numbers in the sheet. I should be able to alter N on the work sheet. How to do? In public sub?
Prime nubers are the nubers that can be divided with 1 or itself in order to create an integer (in case u were wondering).
A Beginner Needs Some Help With Prime Numbers Program
i need some help with a program i want to create about prime numbers from 0 to 10000. I have a problem to end the program.
*With Form1, two Comboxes: (the number 1 means 100, then 100 to 1000), a HScrollbar for timing (max 900s).
Private Sub Command1_Click()
Private Sub Command2_Click()
Private Sub Form_Load()
For a = 1 To 99
Combo1.ListIndex = 0
Combo2.ListIndex = 0
Private Sub Form_Initialize()
Randomize Timer 'initialise la liste des nombres aléatoires
Private Sub Combo1_Click()
For a = Combo1.List(Combo1.ListIndex) + 1 To 100
Combo2.ListIndex = 0
Private Sub HScroll1_Change() 'reglage du chrono avec les touches
Label3.Caption = "Temps : " & HScroll1.Value & " secondes"
Private Sub HScroll1_Scroll() 'reglage du chrono avec la souris
Label3.Caption = "Temps : " & HScroll1.Value & " secondes"
*With Form2, 10 labels, (number of digits should be in relation with intervals of Form1the number 1 means 100, then 100 to 1000; for example,with comboxes, ). Then if i want to study numbers from 300 to 800 in Form2, in Form1 i will take from 3 to 8 interval; 30 to 50 would be from 3000 to 8000; 3309, or 5781, or 4221... every number in the labels ends by 1,3,7 or 9 and i have to confirm in the textboxes with keyboard by "O" means yes the number is a prime number or "N" means the number is not a prime number by clicking on the command button. (red answers are wrong answers)...
"nouvelle partie" means "new deal" and "quitter" means leave.
Private Sub Command1_Click()
'lit l'index la combo1 de la form1 depuis la form2
choix = Form1.Combo1.ListIndex
'On remplit les labels
Label1 = nbalea(inter)
Label2 = nbalea(inter)
Label3 = nbalea(inter)
Label4 = nbalea(inter)
Label5 = nbalea(inter)
Label6 = nbalea(inter)
Label7 = nbalea(inter)
Label8 = nbalea(inter)
Label9 = nbalea(inter)
Label10 = nbalea(inter)
b = Array(1, 3, 7, 9)
nbalea = Int((nombre 10) * Rnd) * 10 + b(Int((UBound(b) + 1) * Rnd))
Then can you help me with this program please ?
PRINTING SERIES OF PRIME NUMBERS
Please,i need to get the correct codes to print series of Prime Numbers depending on the number of first prime numbers the user wants to see.For instance,if i key in 5,the Program needs to print 2,3,5,7,11.Also,i will like to have an idea of how the form will look like.Thank you.
Pick Random Numbers From Prime Number Array
I am wondering if someone can show me how to create an array of prime numbers and then get the vb program to randomly select 2 random number from an array of prime numbers already coded into the program.
The array does not have to be created just a static array with 20 prime numbers for the program to chose from.
I would have 2 text boxes then the program randomly pick 2 random prime numbers and puts them into each of the 2 text boxes.
I have one textbox, I will input 100
how can I get the nearest prime number to it, like 97?
or I input 85, but it will display 83 bec it is the nearest prime
this took em five minutes to make try it out tell me what u think
This is an age-old question. How do u figure out whether a number is prime or not. I've never quite managed this. What if I have to display all prime nos. till a limit(say 1000/2000....not fixed)???
Thanks a lot,
how to findout prime nos between 1 to 10
Prime # Text Box
I have a prime number finder and I am trying to send all of teh primes up to 1,000,000 to my Dad. Right now, it is printing them to a text box with a comma and a space seperating them. Does anyone know how to make a text box hold more than then default? (It got to prime number 99707 and then stopped). If not, hos can I make it go to a new text box in the middle of the loop. If this is not possible, to a file?
i have made a program t see if a number entered into text1.text is prime and it is not working it is just giving the wrng results some prime numbers it says they are nt prime sme nt prime numbers it says they are prime but only sometimes it is right i dont know what i have doen wrong, can someone help me? this is the cde:
Option ExplicitDim calculating As ByteDim prime As BytePrivate Declare Function GetTickCount Lib "kernel32" () As Long Private Sub Command1_Click()If Text1.Text < 10 ThenMsgBox "nuber must be bigger than 10 "Else calculating = TrueDim lngStart As LongDim lngFinish As LongDim lngCounterOne As LongDim lngCounterTwo As LongCommand1.Caption = "calculating..."Form1.Tag = 2Text1.Tag = Str(Val(Text1.Text) - (1))lngStart = GetTickCount()DoIf Text1.Text Mod Form1.Tag = 1 Thencalculating = Falseprime = False ElseForm1.Tag = Str(Val(Form1.Tag) + (1))End IfIf Form1.Tag >= Text1.Tag Thencalculating = Falseprime = TrueEnd IfLoop Until calculating = FalselngFinish = GetTickCount() Label1.Tag = CStr(lngFinish - lngStart)Text2.Text = Str(Val(Form1.Tag) / (1000))If prime = True ThenLabel1.Caption = "number is prime"ElseLabel1.Caption = "number is not prime"End IfCommand1.Caption = "calculated"End If End Sub
I'm making a program that calculates the prime values but it's getting too slow when it comes to values like a million. My method is that i divide the value with all values from 0 to that value, for instance 0 to 10, if the value is 10. But i think you don't have to divide the value with for instance 6 because you can't divide a value with something that is larger than half of the original one. I don't know how but this is something i tried to compress the time it takes to calculate the values, but it's still too slow.
Prime / Base 10
Hey all I need some code for VB6.0 that Provides Conversion of a number in Base 10.
thanks for your help..
By the way I also was looking for a VB6.0 that will display the prime components of an integer entered.. eg. 21 = 7,3 Thanks Again
Getting All The Prime Factors From Any Integer
I was wondering if anybody can help me with some code(vb.net 2003) on how to get all the prime factors of any integer the user put in?
I am a student in SA and I must do a project and one of the things is to get the prime numbers of integer.
Anyone's help would be appreciated!
Please Help...calculate Prime Factor
I am a VB beginner. I have an assignment due tomorrow. But I have no idea how to program this one.
I have to put any number into the input box and find out whether it is prime factor or not. If it is not a prime factor then the picture box displays something like this: 10000 = 2*2*2*2*5*5*5*5. Also I have to use one function and one procedure.
Guys, please help me.
Need Help On Prime Factor Of Number C++
hello im new in learning c++ and i have a headache wrting a program of prime factor of a number..i have an example 12=1*2*2*3 but i dont know how to begin with this program?can anyone here help me please thank you
Fast Prime Number App
I started quite a while ago to make a program that were able to find out if a number was a prime number, then it was just to loop it.
I want some feedback on it, and if someone have made a similar program, you might tell me what you think about the performance.
It might look strange that you can choose between a Slow, Fast, UberFast and Accelerated algorithm, but that's because I had to keep the old algorithms and compare the results to be sure the don't differ on anything but the speed.
Uberfast is the one to be the fastest, Accelerated must start on 2 and is the fastest on a range from 2 to ~2000, because it dynamically uses generated prime numbers to test new numbers (fastest on lower numbers).
When you try it, do a benchmark by pressing Ctrl+Alt+Shift+B, then click the Benchmark button. It will then generate a result, please copy it and paste it here if you would like to.
I know it fails on finding out what cpu and windows you run, so type it in by hand... I'd like to see what performance other people get .
Edit: Attachment removed - no compiled binaries please - Posting Guidelines
Determining The Prime Number
help me pls...can I have the code in determining if the number that i have inputted is a prime number or not using a loop...thanks!!
Prime Number Finder
Idk how to do this... please help me... here is what I have so far to find prime numbers it is wrong.
Dim intNumber As IntegerPrivate Sub cmdFindOut_Click() intNumber = txtEnter.Text If intNumber Mod 2 Then MsgBox "It's not Prime!!" End If End Sub
Mersenne Prime Algorithm
I don't know if you've heard of Prime95 or GIMPS or www.mersenne.org but i'm kinda interested in that stuff. I want to make a Visual Basic version of it. It checks extremely large numbers and sees if their prime. I know that some of you would say that VB is too slow for this, but that really isn't a problem for me - i'm fine with it. I've got two problems right now. The first problem is that i don't exactly know what the fastest algorithm is for finding mersenne primes. How would i go about coding. Do I use Lucas-Lehmer methods? Second of all - if a user puts in a large exponent (such as 13000) there will be a overflow in VB no matter what type i'm using. Is there a way to get the actual number value of 2^13000 by using arrays and strings? I've seen an example at PSC where something like that is done. But the code is extremely long because the author has a huge math library and nothing is commented. Can anyone help me out? Thanks
Prime Common Factors
Help I need to write a program to find all the prime common factors of 2 numbers. The user has to enter in 2 numbers and the output will be the prime common factors
LifeView Prime 30 TV Card API?
The program I got with my TV Card (LifeView Prime 30) sux, so I want to build my own. One of the reasons is to make an advanced recording engine that will get the list of shows from an internet page and auto-record my favorite programs during the week.
There must be some API Functions to help build one. I looked in the APIGuide by kpd-team and there's nothing there (www.allapi.net, if you're interested).
I'm most familiar with VB so i'm gonna try it first. If it's impossible I'll use MFC or C++.
I did a search and came up with this: http://www.codeguru.com/forum/showt...ighlight=moretv , which is for C++, and MoreTV is dutch or swedish, hehe, can't read it
Can anyone help me? Give me some pointers?
Getting Prime Factors For Any Input Integer
I have poured through the threads here as best I can, but still have not been able to pin down the answer I seek. What I am trying to accomplish is to bring up a text input box, have a whole number put in and then have the program factor all the numbers to prime.
Ex: Start with the number 24
The factors of course would be 2,2,2,3. I understand how to do it, but actually telling the code the formula is making me crazy. I have tried Do While and If and well you get the idea.
I am obviously new to this, but trying to learn from a book. Here is what I have managed to get working so far. I have tried a number of ideas from the site but all to no avail.
Dim intentry As Long
Dim n As Single
Dim num As Single
Dim count As Single
Dim flag As Boolean
num = Val(InputBox("Enter any whole number greater than 0"))
If num < 0 Then
MsgBox "Please enter a positive integer"
Val (InputBox("Enter any whole number greater than 0"))
ElseIf num = 1 Then
MsgBox "1 is a given prime, please enter another positive integer"
Val (InputBox("Enter any whole number greater than 0"))
ElseIf num = 2 Then
MsgBox "2 is a given prime, please enter another positive integer"
Val (InputBox("Enter any whole number greater than 0"))
I appreciate any help you feel is appropriate.
Escaping Strings For Mysql - Prime Character
I'm trying to read in text and write it into a mysql database. Works fine so far till I hit a text with single quote in it - but it is a weird single quote:
΄ <- this is how it looks like. placing it in vb gives me question mark ?
I guess it is the prime character, in Unicode it's U+2032.
Question is, how can I do a replace in VB for U+2032?
Prime Number Algorithm Question Newbie
I'm new to VBA as you can probably tell. But i need some help with a code i've created.
I've made a form that will generate prime numbers, and i want to be able to create 2 text boxes where the user can enter the range in which to find the prime numbers.
Here is my code..
Private Sub cmdOK_Click()
For i = 2 To 1000
For j = 2 To i - 1
If (i Mod j) = 0 Then
If j = i - 1 Then Me!Text9 = Me.Text9 & " " & i
As you can see the "2 To "1000" needs to be changed to the names of the two text boxes?
Many thanks for any help you can give. Yes this is very basic..lol
Designing A Software To Automatically Control The Generator's Prime Mover
dear all forum friend,
i have this problem which i need to came up with a solution using VB programming. i'm not really familiar wit the program, so i'm askin for anyone who can help me out. i was about to design a software ( more like a syatem ) which will then automatically controlling the generators prime mover to meet the load demand. my problem is how i'm going to connect or send a signal to the hardware ( device ) i.e the circuit breaker with a command from the VB?is there anyone can help me?
What Is The Maximum Size (largest) Prime Number That Can Be Generated Using VB Datatypes?
I am coding an application for teaching the RSA algorithm. I have been able to generate random (using the rnd function) prime numbers upto 32 bits using the "long" data-type. However, since the "double" data-type with 8 byte memory allocation is available I should be able to generate prime numbers of 64 bits size. However, this is causing problems as the rnd function module shows run time error '6' ---- overflow. Any help that I can get would be wonderful. Time for me is DEFINITELY at a premium!!!!
Edited by - Arian_King on 4/29/2008 11:53:37 AM
[SOLVED]FormatCurrency Returns Numbers As Text Instead Of Formatted Numbers
This seems as a really dumb question but..... why is it that numbers resulting from a calculation work perfectly BEFORE I format them as currency and DO NOT work as numbers after I have formatted them?
Code:frmDCashFlow.Text7.Text = Val(frmDCashFlow.Text4.Text) + Val(frmDCashFlow.Text5.Text) + Val(frmDCashFlow.Text6.Text) 'This returns a value... OK
frmDCashFlow.Text7.Text = FormatCurrency(frmDCashFlow.Text7.Text, 0) ' This returns numbers as text, that can't be used to calculate once formatted....
Why and how can I avoid this? The FormatCurrency function is supposed to return a numeric expression formatted as currency value.....
Thanks for any help
Edited by - vbprog1144 on 10/26/2004 1:00:34 PM
Converting String Numbers Into Real Numbers
I have a formula in VBA that searches through a table for corresponding results to the conditions I specified and sort the results into another table. My problem is that the data I use, which includes monetary values, seems to have converted them into string numbers (which include de $ sign as part of the characters and not only into a simple visual effect). It's a problem when I want to do mathematic operations with those monetary values. Is there a way to convert them into real numbers in my VBA code just before doing my maths with them? I tried to pre-format the cells before their extraction but it seems it isnt enough to really convert them.
Splitting Large Numbers Into Smaller Numbers
i want to divide a decimal into smaller decimals in an array form.
starting with 0.22335566
array(0) = 0.22
array(1) = 0.0033 or 3.3 *10-2
array(2) = 0.000055 or 5.5*10-4
can anyone help?
thanx a million
How Do You Convert Whole Numbers To Decimal Point Numbers?
I have this code and it adds 9+9 then divides by 4 which = 4.5 and places it in a text box, but it dosn't show the 5 after the point.
Code:a = 9: b = 9
text(8).text = a+b
text(8).text = text(8).text 4
text(8).text = Format(text(8).text, "#.##")
Whats wrong here?
Edited by - Bob K on 3/17/2005 7:17:06 PM