Output Prime Numbers and Prime Factors

Category:
Dates and Math
Type:
Snippets
Difficulty:
Intermediate

Author: Richard Deeming

Version Compatibility: Visual Basic 6

More information:
This code outputs all prime numbers up to the limit of the VB double type to the debug window, a text file, and a text box. In addition, it has the ability to optionally include non-prime numbers, and demonstrates factorizing these into a sequence of prime factors. You can also specify the number to start at, allowing you to stop processing and get on with some work, and resume processing at a later time, starting where you left off.

To use the code, create a form with one button (cmdCancel) with a caption of "Start", one check-box (chkNonPrime) with a caption of "Include non-primes", and one text-box (txtPrime). Paste the code into the form's module, and run. Click the "Start" button to start listing primes, tick the checkbox to include non-primes, or enter a number in the textbox to specify a starting point.

Instructions: Copy the declarations and code below and paste directly into your VB project.

Declarations:

Code: