Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() I am relaunching my earlier request which was lost in traffic and this time hoping it will catch the eye of would-be benefactors. Many thanks. Myles davidmy wrote: [b]I am looking for a way to recursively mimic the FACTORIAL function. The lesson thus learnt will lead me on to revamp a routine I am currently working on. Here is my botched attempt. Sub Test() x = Fat(10) Msgbox x End Sub Function Fat(n as Integer) If n < 1 Then Exit Function Fat = n * Fat(n-1) End Function Code returns 0 for any value of n. TIA Myles -- davidmy ------------------------------------------------------------------------ Posted via http://www.mcse.ms ------------------------------------------------------------------------ View this thread: http://www.mcse.ms/message2500073.html |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi
You havn't specified the value of Fat when n = 1, so the code assumes it is 0. Try Sub Test() x = Fat(10) MsgBox x End Sub Function Fat(n As Integer) As Long If n < 1 Then Exit Function If n = 1 Then Fat = 1 Else Fat = n * Fat(n - 1) End If End Function You need the output value as long not integer or you will get an overflow error. regards Paul davidmy wrote: I am relaunching my earlier request which was lost in traffic and this time hoping it will catch the eye of would-be benefactors. Many thanks. Myles davidmy wrote: [b]I am looking for a way to recursively mimic the FACTORIAL function. The lesson thus learnt will lead me on to revamp a routine I am currently working on. Here is my botched attempt. Sub Test() x = Fat(10) Msgbox x End Sub Function Fat(n as Integer) If n < 1 Then Exit Function Fat = n * Fat(n-1) End Function Code returns 0 for any value of n. TIA Myles -- davidmy ------------------------------------------------------------------------ Posted via http://www.mcse.ms ------------------------------------------------------------------------ View this thread: http://www.mcse.ms/message2500073.html |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
vlookup failure & ctrl-f failure? | Excel Discussion (Misc queries) | |||
Sum function failure | Excel Worksheet Functions | |||
Create a function to calculate Mean time Before Failure | Excel Worksheet Functions | |||
add in failure | Excel Programming | |||
If .,AND ... Then failure | Excel Programming |