To help others know how to use your function, you can define a usage message. Out[8]= | |
The usage message is used by the Mathematica Function Wizard to automatically generate argument templates for the function. To be fully compatible with the Function Wizard, you should always use the following convention for your usage messages. Out[9]= | |
You can also define a set of default options for your functions, if needed. Out[10]= | |
This clears the previous definition for the function, then defines it with options.
When you are developing a function that will be used in Excel, you should consider returning the symbol $Failed if something goes wrong in your function. You can do this using the Check function. The symbol $Failed is converted to a #VALUE! error in Excel that will suppress further dependent calculations. Out[15]= | |
To be complete, you should also create a catch-all function definition that will handle the case where users provide arguments that do not match the pattern you specified. By default, the function returns unevaluated. Out[16]= | |
This traps the error. Out[18]= | |
You can also create your own error messages to inform the user about what went wrong. Out[20]= | |
Out[21]= | |
|