Friday, March 7, 2014

VB 6.0 Code for Getting all the Primes of a Number

Hello students!
This article is going to discuss about the Visual Basic 6.0 code on how to find or get all the primes of the number entered by the user.























In getting primes of a number you must consider the following objects:

1. one form
  • Form1-has a caption of  "Getting Prime Numbers of an Integer"
2. one label
  • Label1 - has acaption of "Enter Number:"
3. One textbox
  • Textbox1 - is where an integer to be get the primes will be inputted (Text: must be emptied)
4. one listbox
  • List1-is where all the prime numbers of an integer will display
5. one command button
  • Command1 -use for an action, which will produce all prime numbers of an integer (Caption: Get Primes)
















SOURCE CODE:

Dim num, counter, x, y As Integer
Private Sub Command1_Click()
On Error GoTo handler:
List1.Clear
counter = 0
num = CInt(Text1)

For x = 2 To num
     counter = 0
    For y = 2 To num
        If x Mod y = 0 Then
            counter = counter + 1
        End If
    Next
    If counter < 2 Then
        List1.AddItem x
    End If
Next x
Exit Sub

handler:
    MsgBox "Not a number", vbExclamation, "Status"
End Sub


If you want the JAVA code for getting all the factors of an integer just click
For more information keep checking itlibraryetc.blogspot.com

No comments:

Post a Comment