question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Function returns a #VALUE! when it should return #NAME?

See original GitHub issue

Hello guys! In Excel: =HelloWorld(TRUF) Returns "Hello World!" even if parameter TRUF returns #NAME? in Function Argument Window (Ctrl + A). =HelloWorld(TRUF) should return #NAME?.

C# Code:

using ExcelDna.Integration;

public static class MyFunctions
{
    [ExcelFunction(Description = "Hello world")]
    public static string HelloWorld(
[ExcelArgument("True or False?")] bool foo)
    {
        return "Hello World!";
    }
}

Thanks

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:18 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
govertcommented, Jan 15, 2018

Your object will be of type ExcelError which is an enum. This function describes the parameter:

				// This function returns a string that describes the argument value.
				// For arguments defined as 'object' type, this shows all the possible types that may be received.
				// Also try this function after changing the 
				// [ExcelArgument(AllowReference=true)] attribute.
				// In that case we allow references to be passed (registered as type R). 
				// By default the function will be registered not
				// to receive references but that actual target value - AllowReference=false (type P).
				[ExcelFunction(Description="Describes the value passed to the function.", IsMacroType=true)]
				public static string Describe([ExcelArgument(AllowReference=false)]object arg)
				{
						if (arg is double)
							return "Double: " + (double)arg;
						else if (arg is string)
							return "String: " + (string)arg;
						else if (arg is bool)
							return "Boolean: " + (bool)arg;
						else if (arg is ExcelError)
							return "ExcelError: " + arg.ToString();
						else if (arg is object[,])
							// The object array returned here may contain a mixture of different types,
							// reflecting the different cell contents.
							return string.Format("Array[{0},{1}]", ((object[,])arg).GetLength(0), ((object[,])arg).GetLength(1));
						else if (arg is ExcelMissing)
							return "<<Missing>>"; // Would have been System.Reflection.Missing in previous versions of ExcelDna
						else if (arg is ExcelEmpty)
							return "<<Empty>>"; // Would have been null
						else if (arg is ExcelReference)
              // Calling xlfRefText here requires IsMacroType=true for this function.
							return "Reference: " + XlCall.Excel(XlCall.xlfReftext, arg, true);
						else
							return "!? Unheard Of ?!";
				}
1reaction
Cronancommented, Jan 17, 2018

Thanks for this @govert

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to name functions with multiple return values
Function names should not describe their return value, at least not inherently. A function should describe what the function's purpose is.
Read more >
python - How to write a function to return the variable name?
When you pass something to a function, you are passing the object, not the name. The same object can have many names or...
Read more >
Function return values - Learn web development | MDN
When the function completes (finishes running), it returns a value, which is a new string with the replacement made. In the code above,...
Read more >
2.2 — Function return values (value-returning functions)
First, your function has to indicate what type of value will be returned. This is done by setting the function's return type, which...
Read more >
12.5. Returning a value from a function
The return statement is followed by an expression which is evaluated. Its result is returned to the caller as the “fruit” of calling...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found