LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 65
Default How to return an error code from a function

On 5 Feb, 17:05, "Peter T" <peter_t@discussions wrote:
Not sure why you say 'err' can't be passed back to the caller, simply

MySqrt = err
or as an additional argument

If you declare err As Long rather than as a boolean would enable you to pass
more in the way of information, eg the error number itself


Hi, Peter,

thanks for the reply. The problem is that my actual code is more
complex than this. MySqrt cannot have negative values, so assigning a
negative value to err and passing that back would allow the caller to
understand if MySqrt found an error or not. However, my real function
(let's call it MyFun) can assume any real value, from negative to
positive. So I cannot just assign a numerical value to err and pass it
back.


In passing, although worksheet functions are extremely efficient in cells
the overhead of calling them in VBA makes them relatively slow, where viable
better to roll your own, eg

result = X ^ (1 / nRoot)

maybe include the root as an argument,
(args, Optional nRoot as Long = 2)


Very interesting, I didn't know that.


BTW, your *'Exit Function' is redundant


You're right, I just wrote the code as an example of a possible
function so I didn't check for redundancies.


Regards,
Peter T


Thanks,

Best Regards,

deltaquattro
 
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
Unknown error in function, and how to return value? Chris Excel Worksheet Functions 3 May 22nd 09 01:59 AM
Mode function - return default value rather than #N/A error if no Struggling in Sheffield[_2_] New Users to Excel 4 March 27th 09 06:27 PM
Weibull function return an error avi Excel Programming 0 November 20th 08 09:10 PM
Error Return Value from and INDEX(A:2,MATCH()) function BJ Excel Worksheet Functions 4 January 26th 05 02:59 PM
Excel return error code Gary Lam Excel Programming 2 August 18th 03 06:19 PM


All times are GMT +1. The time now is 04:11 AM.

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"