It looks like you're new here. If you want to get involved, click one of these buttons!

- 141K All Categories
- 103.8K Programming Languages
- 6.5K Assembler Developer
- 1.9K Basic
- 40K C and C++
- 2.9K C#
- 7.9K Delphi and Kylix
- 4 Haskell
- 9.7K Java
- 4.1K Pascal
- 1.3K Perl
- 2K PHP
- 551 Python
- 37 Ruby
- 4.4K VB.NET
- 1.6K VBA
- 20.9K Visual Basic
- 2.6K Game programming
- 317 Console programming
- 92 DirectX Game dev
- 1 Minecraft
- 112 Newbie Game Programmers
- 2 Oculus Rift
- 9K Applications
- 1.8K Computer Graphics
- 744 Computer Hardware
- 3.5K Database & SQL
- 535 Electronics development
- 1.6K Matlab
- 628 Sound & Music
- 258 XML Development
- 3.3K Classifieds
- 199 Co-operative Projects
- 198 For sale
- 190 FreeLance Software City
- 1.9K Jobs Available
- 604 Jobs Wanted
- 210 Wanted
- 2.9K Microsoft .NET
- 1.8K ASP.NET
- 1.1K .NET General
- 3.4K Miscellaneous
- 7 Join the Team
- 355 Comments on this site
- 70 Computer Emulators
- 2.1K General programming
- 187 New programming languages
- 628 Off topic board
- 217 Mobile & Wireless
- 89 Android
- 126 Palm Pilot
- 340 Multimedia
- 156 Demo programming
- 184 MP3 programming
- Bash scripts
- 27 Cloud Computing
- 53 FreeBSD
- 1.7K LINUX programming
- 370 MS-DOS
- Shell scripting
- 321 Windows CE & Pocket PC
- 4.1K Windows programming
- 942 Software Development
- 417 Algorithms
- 68 Object Orientation
- 92 Project Management
- 95 Quality & Testing
- 269 Security
- 7.7K WEB-Development
- 1.8K Active Server Pages
- 62 AJAX
- 5 Bootstrap Themes
- 55 CGI Development
- 28 ColdFusion
- 224 Flash development
- 1.4K HTML & WEB-Design
- 1.4K Internet Development
- 2.2K JavaScript
- 37 JQuery
- 308 WEB Servers
- 151 WEB-Services / SOAP

Terms of use / Privacy statement / Publisher: Lars Hagelin

Programmers Heaven articles / Programmers Heaven files / Programmers Heaven uploaded content / Programmers Heaven C Sharp ebook / Operated by CommunityHeaven

© 1997-2017 Programmersheaven.com - All rights reserved.

## Comments

1,784:

This forum is for basic, not vb.

And it's acctually for qbasic.

67✭Read here prime numbers

4✭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 •.

2✭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