Login  Register

Re: "Numeric return value expected" when assigning array to a user-defined function that returns a string

Posted by Herbie on Oct 21, 2016; 5:13pm
URL: http://imagej.273.s1.nabble.com/Numeric-return-value-expected-when-assigning-array-to-a-user-defined-function-that-returns-a-string-tp5017447p5017448.html

God day Noname,

is this

//////////////////////////////
str_list = newArray(1); // strings
num_list = newArray(1); // numbers

str_list[0] = "" + str_fx("TEST");
print(str_list[0]);

num_list[0] = num_fx(9);
print(num_list[0]);

function str_fx (string) {
        string += "fx";
        return string;
}

function num_fx (num) {
        return num*num;
}

//////////////////////////////

what you wish to achieve?

Best

Herbie

:::::::::::::::::::::::::::::::::::::
Am 21.10.16 um 18:36 schrieb sokipdx:

> I am trying to assign an element of an array to a user-defined function that
> returns a string, but I get an error when I run this code:
>
>
>
> str_list = newArray(1); // strings
> num_list = newArray(1); // numbers
>
> str_list[0] = str_fx("TEST");
> num_list[0] = num_fx(9);
>
> function str_fx (string) {
> return string+"fx";
> }
>
> function num_fx (num) {
> return num*num;
> }
>
>
>
>
> I get the error:
> Numeric return value expected in the following line:
> str_list[0] = str_fx("TEST" <)>;
>
> Oddly, the num_fx function that returns a number works when assigning to an
> array element.

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html