View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
John Coleman John Coleman is offline
external usenet poster
 
Posts: 274
Default Factorial Function

The line "lblResult.Text = sum" keeps overwriting the old text.
Try something like lblResult.Text = lbl.Text & vbCrLf & sum

hope that helps

-John Coleman



On Feb 19, 2:49 pm, wrote:
Okay so I have a label with the ID = lblResult. I want to display
each factorial of 1 through five. But when I run my program it only
displays the value of 5!. Can someone help me put the values of 1! -
4!? I would like it to display as follows:

1
2
6
24
120

or

1, 2, 6, 24, 120

Here is my code:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim n, sum As Integer
getFactorial(n, sum)

End Sub
Private Function getFactorial(ByVal n As Integer, ByRef sum As
Integer) As Integer
Dim i As Integer
n = 0
sum = 1
For i = 1 To 5
n = n + 1
sum = n * sum
lblResult.Text = sum
Next i
End Function

Thanks! =)