Using Table.set to put non-numeric values into a table

Hello, I am using Table.set to write the result obtained from a function to a table. Sometimes this result is numeric, sometimes it is text. In the latter case, I cannot use the function directly in the Table.set-command, as I would get the error:

Numeric return value expected in line ...

The following code illustrates the issue:

//example 1
//this code works:
function doCalculation() {
	result = "text";
	return result;
result = doCalculation();
Table.set("columnName", 0, result, "TableName");
//example 2
//this code returns error "Numeric return value expected in line ...":
function doCalculation() {
	result = "text";
	return result;
Table.set("columnName", 0, doCalculation(), "TableName");

Table.set has no problem when results is numeric, but fails to take the text as a value when it directly comes from the function (but not when it comes from a pre-defined variable).
Since I’m not experience with the coding features, I wonder if this is the supposed behaviour and I certainly need to go the way of pre-defining results in the first step (as in example 1).
Thanks already!


This is a limitation of the macro language that shows up every once in a while. While not the ‘supposed’ behaviour, it is known.
I recall struggling with the same thing, which ended up distilling into the same practice as you:

avoid using macro functions as inputs of other functions

Though I do not recall if this is anywhere in the documentation.

1 Like

Example 1 shows that using the function to define the variable and subsequently using the variable in Table.set works.
Example 2 shows that using the function directly fails
I probably should have left results = 2; out completely from the examples as it did not serve any purpose (except that when exchanging it with results = "text"; example 1 and 2 both work) - that was probably misleading

Do you know/remember any place where this was discussed/documented?

@MojoDodo I recommed going for a full-fledged scripting language (such as Groovy or Jython) for any more complicated tasks :slight_smile:

Before posting my question in the forum, I was reading this:, so this might be a good place to document/metion it.