One of the most fascinating inventions made by man is the
computer. We use computers in our day to day activities such as in business,
education, research, military applications, communications as well as
entertainment. This computer becomes useful when there is software that runs on
it. As we all know software is a collection of programs that makes our computer
useful and interesting to work with. There two classifications of software that we
use in our computer system they are application software and system software.
The first type of software is application software this type of software was
designed to solve common problems that we encounter just like a word processing
program like Microsoft Word we use this program to create and print our
documents, computer games for instance is a good example of application
software it was designed not only to entertain us but also it develops our
thinking skills in making decisions and analysis of the situation.
On the other
hand system software was created to maintain the overall operation of our
computer system examples of this is operating system that manages all the
software and hardware components installed in our computer. Another example is
your antivirus software which protects your computer against computer viruses
that will damage our files and disable the normal operation of our computer in
general.
In this article I will discuss about the program that I
considered as application software by its nature I called this program Find the
Prime Numbers. Let me explain in the
first place what is a prime number is an number that is bigger than one and does not
have a positive divisor other that one and itself. We have learned the prime numbers during our
elementary and high school days. Examples of prime numbers is 2,3,5,7,11,13,17,19, 23 and 29 for instance.
In this program I will be using Visual Basic 6 as my programming language to
illustrate of program Find Prime Number. I choose Visual Basic 6 because it is
very easy to use and its ability to create sophisticated user interface
compared to other programming language that you are the one who will write the
statements for its design and layout stage. Having this advantage of Visual
Basic 6 we can cut down big amount of our development time and we can focus on
solving the problem on hand.
For our program the first thing that
will do is to create the form and put a series of objects two command buttons,
a list box where the list of prime number will be listed. The first command
button is Find the Prime Number when the user click that button it will ask the
user using a dialog box to enter the starting value of the number after the
user give the initial values our program will ask the user to enter the last
range or the maximum number which the generation of prime numbers will be stop.
When the user press the enter key the
program will list the values of prime numbers from the given parameters earlier
by our user. Below is the command button
cmdPrime for checking if the starting number and the end number by the user and
then it will perform a series of computation to find the list of prime numbers.
The result will be displayed in the list box adjacent to our command buttons.
Private Sub cmdPrime_Click()
lstResults.Clear
lblResults = "Results:"
lngStart = InputBox("Enter the beginning number:", "Start
Number")
lngEnd = InputBox("Enter the ending number:", "End
Number")
lngStart = lngStart + 1
Do Until lngStart = lngEnd
If PrimeStatus(lngStart) = True Then
lstResults.AddItem Str(lngStart)
lngCount = lngCount + 1
Else
End If
lngStart = lngStart + 1
Loop
lblResults = lblResults & " " & Str(lngCount)
lngCount = 0
End Sub
This is the function that we have
created to perform the computation and analysis of values of prime numbers in
our program.
Function PrimeStatus(TestVal As Long)
As Boolean
Dim Lim As Integer
PrimeStatus = True
Lim = Sqr(TestVal)
For I = 2 To Lim
If TestVal Mod I = 0 Then
PrimeStatus = False
Exit For
End If
Next I
End Function
This is the general declaration of our
variables it means we can use this variables anywhere in our program.
Public lngStart As Long
Public lngEnd As Long
Public lngCount As Long
Quit command button when the user
click this button our program will be terminated and will return to our
operating system.
Private Sub cmdExit_Click()
End
End Sub
I just hope that you have learned
something new about programming with this article Find the Prime Numbers using
Visual Basic 6. If you have some comments, suggestions about this article feel
free to email me I will be grad to answer your questions.
Thank you very much and Happy
Productive Programming.
If you have some questions please send me an email at jakerpomperada@yahoo.com and jakerpomperada@gmail.com.
Sample Program Output
No comments:
Post a Comment