hey i learnd vb 2 years ago and i kinda forgot how to use it but im trying to make a program that creates all the prime numbers up to 1000 so if anyone has any help or ideas on what to do it would be great
: hey i learnd vb 2 years ago and i kinda forgot how to use it but im trying to make a program that creates all the prime numbers up to 1000 so if anyone has any help or ideas on what to do it would be great :
This forum is for basic, not vb. And it's acctually for qbasic.
Prime Numbers From "Porter's books for the commodore 64"
For a simpler example in old timey basic:
Primes are numbers that cannot be divided without producing a
fraction, or, in other words, numbers only divisible by 1 or by
themselves. An example is the number 5: there are no numbers
that you can multiply except 1 and 5 to produce 5, and as a result,
5 is prime. In a sense, this is the opposite of the preceding program in that it finds numbers for which there are no factors.
A program that computes all the prime numbers from 1 to an
upper limit eN) is called the Sieve of Eratosthenes. It does a
gigantic amount of work, for an admittedly trivial result. Computer
people use a Sieve to compare the speeds of two or more machines
or of two or more programming languages running on the same
computer, in order to find out which is the most efficient. This
process is called "benchmarking," and it often plays an important
part in selecting a particular product over others.
These are several ways of calculating prime numbers. It's not
important which method is used in benchmarks, so long as the
same method is used consistently for all tests. This program multiplies all the numbers from 2 to N/2 and marks a list for each
product. The second phase then scans the list and prints all the
entries not marked, which are the prime numbers. Consequently,
the list has "holes" indicating the prime numbers, hence the
analogy to a sieve.
Because the purpose of this kind of program is usually to measure running time for the calculations, the program times itself
during that phase. At the end of the list, it reports how many
~econds it took to compute all nonprime numbers. Output time is
not measured. If the screen fills, the program pauses until you
press RETURN. Beware: The higher the limit, the longer this
program runs, and time increases as the square of the limit. If you
set the limit at something huge like 10000, go to bed and come
back in the morning; the Commodore 64 sets no speed records.
NEW
190 REM ** ERATOSTHENES SIEVE
119 PRINT CHRS(147): PRINT
129 PRINT ·PRIME NUMBERS·
139 INPUT· UP TO WHAT-; N
149 DIM PX(N)
159 PRINT: PRINT -THINKING-
169 Tl = TIME
179 FOR X = 2 TO (N / 2)
189 FOR Y = 2 TO (N / 2)
199 I = X * Y
299 IF I > N THEN 229
219 P"I.(I) = 1
229 NEXT Y
239 NEXT X
249 T2 = TIME
258 REM ** DISPLAY RESULTS
269 I = e
270 FOR X = 1 TO N
289 IF PX(X) (> 0 THEN 320
299 PRINT X,
389 I = I + 1
318 IF I = 96 THEN GOSUB 370
320 NEXT X
338 ET = (T2 - Tl) / 60
349 PRINT
359 PRINT RELAPSED TIME =" TT ·SEC·
360 END
370 REM ** FULL SCREEN
380 PRINT ·PRESS RETURN FOR MORE ••• •
~98 GET X$: IF X$ = aH THEN 398
i499 I = 9: RETURN
RUN
Sample run:
PRIME NLt1BERS
UP TO WHAT? 390
THINKING
123 5
7 11 13 17
19 23 29 31
37 41 43 47
53 59 61 67
71 73 79 83
89 97
ELAPSED TIME = 21.75 SEC
READY •.
Here it is
Private Sub cmdPrime_Click()
Dim p, n, i As Integer
p = 1
Print “Prime Numbers are : ”
For n = 1 To 100
For i = 2 To n – 1
If n Mod i = 0 Then
p = 0
Exit For
Else
p = 1
End If
Comments
:
This forum is for basic, not vb.
And it's acctually for qbasic.
Read here prime numbers
Prime Numbers From "Porter's books for the commodore 64"
For a simpler example in old timey basic:
Primes are numbers that cannot be divided without producing a
fraction, or, in other words, numbers only divisible by 1 or by
themselves. An example is the number 5: there are no numbers
that you can multiply except 1 and 5 to produce 5, and as a result,
5 is prime. In a sense, this is the opposite of the preceding program in that it finds numbers for which there are no factors.
A program that computes all the prime numbers from 1 to an
upper limit eN) is called the Sieve of Eratosthenes. It does a
gigantic amount of work, for an admittedly trivial result. Computer
people use a Sieve to compare the speeds of two or more machines
or of two or more programming languages running on the same
computer, in order to find out which is the most efficient. This
process is called "benchmarking," and it often plays an important
part in selecting a particular product over others.
These are several ways of calculating prime numbers. It's not
important which method is used in benchmarks, so long as the
same method is used consistently for all tests. This program multiplies all the numbers from 2 to N/2 and marks a list for each
product. The second phase then scans the list and prints all the
entries not marked, which are the prime numbers. Consequently,
the list has "holes" indicating the prime numbers, hence the
analogy to a sieve.
Because the purpose of this kind of program is usually to measure running time for the calculations, the program times itself
during that phase. At the end of the list, it reports how many
~econds it took to compute all nonprime numbers. Output time is
not measured. If the screen fills, the program pauses until you
press RETURN. Beware: The higher the limit, the longer this
program runs, and time increases as the square of the limit. If you
set the limit at something huge like 10000, go to bed and come
back in the morning; the Commodore 64 sets no speed records.
NEW
190 REM ** ERATOSTHENES SIEVE
119 PRINT CHRS(147): PRINT
129 PRINT ·PRIME NUMBERS·
139 INPUT· UP TO WHAT-; N
149 DIM PX(N)
159 PRINT: PRINT -THINKING-
169 Tl = TIME
179 FOR X = 2 TO (N / 2)
189 FOR Y = 2 TO (N / 2)
199 I = X * Y
299 IF I > N THEN 229
219 P"I.(I) = 1
229 NEXT Y
239 NEXT X
249 T2 = TIME
258 REM ** DISPLAY RESULTS
269 I = e
270 FOR X = 1 TO N
289 IF PX(X) (> 0 THEN 320
299 PRINT X,
389 I = I + 1
318 IF I = 96 THEN GOSUB 370
320 NEXT X
338 ET = (T2 - Tl) / 60
349 PRINT
359 PRINT RELAPSED TIME =" TT ·SEC·
360 END
370 REM ** FULL SCREEN
380 PRINT ·PRESS RETURN FOR MORE ••• •
~98 GET X$: IF X$ = aH THEN 398
i499 I = 9: RETURN
RUN
Sample run:
PRIME NLt1BERS
UP TO WHAT? 390
THINKING
123 5
7 11 13 17
19 23 29 31
37 41 43 47
53 59 61 67
71 73 79 83
89 97
ELAPSED TIME = 21.75 SEC
READY •.
Here it is
Private Sub cmdPrime_Click()
Dim p, n, i As Integer
p = 1
Print “Prime Numbers are : ”
For n = 1 To 100
For i = 2 To n – 1
If n Mod i = 0 Then
p = 0
Exit For
Else
p = 1
End If
Learn VB here https://hackr.io/tutorials/learn-visual-basic-vb