Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Function failure


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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default Function failure

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
vlookup failure & ctrl-f failure? joemeshuggah Excel Discussion (Misc queries) 4 December 22nd 08 07:22 PM
Sum function failure HighFlier22 Excel Worksheet Functions 6 May 25th 08 08:41 AM
Create a function to calculate Mean time Before Failure RMC Excel Worksheet Functions 0 November 3rd 06 01:34 AM
add in failure solo_razor[_41_] Excel Programming 1 December 5th 03 01:01 PM
If .,AND ... Then failure Pete T[_2_] Excel Programming 1 October 22nd 03 08:17 PM


All times are GMT +1. The time now is 09:27 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"