(sorry not sure)
I'm guessing your making a calculator that deals with Factorials ( ! )
If so maybe VB already can do them, just use the factorial symbol ;)
[edit] ^ that didn't work i tryed. so try what i posted underneath. good luck.
Public Function Factorial(n As Byte) As Long
Static f() As Long 'stores the factorials calc thus far
Static h As Long 'stores the highest numbered facorial so far
'if we haven't calc that high yet, then redim and perserve!
If h < n Then
ReDim Preserve f(0 To n) As Long
End If
'set the first two manually!
'i would have an "If" here, but it wasn't working, so, yea
f(0) = 1
'now, if we hadn't gotten to the high value, loop from the
' next value to the one we want, calculating each time
Dim x As Integer
For x = h + 1 To n
f(x) = f(x - 1) * x
Next
heres another way t do it:
Dim Input as single
Dim Output as Single
Output=Input
for x= input to 2
Output=Output*( Input-1)
next x
'where input is the number befor the factorial sign(!), and output is well your output
nice an simple as the factorial is the number multiplied by number- 1, untill number-1= 1 as if it went till number=1 then you would multiply by 0 and poof pointless :P
Comment