Walk Lightly on this PLANET and yet leave such a FOOTPRINT that cannot be erased for thousands of Years..!!!
Visit Codstech for Cyber Security related Posts !

Visitors

Wednesday, July 27, 2011

VB - 69 : Factorial of a Number

Write a VB program to collect a positive integer from the user and list all the factors in a multi-line textbox.
Note : The factor of an integer "n" is any integer that devides "n" completely.

Have a look at Print Even numbers upto n

Refer Collect and List positive integers  also.

(A)Program Design : 


(B) Property(Controls Used) :
  • 2 Labels "Input" and "Factors"
  • 2 Text Boxes (to input number from the user-Text1 and to display the result-Text2 (Multiline-True))
  • One Command Button(Generate Factors)

(C) Attaching Code to the Object :


Private Sub Command1_Click()
Dim no, i As Integer
no = Val(Text1.Text)
Text2 = ""
i = 1

While i <= no
If no Mod i = 0 Then
Text2 = Text2 & i
If i = no Then
Text2 = Text2 & "."
Else
Text2 = Text2 & ","
End If
End If
i = i + 1
Wend
End Sub


(D) Output :

====================================================================
===========================================================

No comments: