Thursday, February 27, 2014

VB 6.0 Code for Getting all the Factors 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 factors of the number entered by the user.



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

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




SOURCE CODE:

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

For x = 1 To num
    If num Mod x = 0 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 a number just click
For more information keep checking itlibraryetc.blogspot.com

No comments:

Post a Comment