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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

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

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.
Reply | Threaded
Open this post in threaded view
|

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

Herbie
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
Reply | Threaded
Open this post in threaded view
|

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

sokipdx
Thank you Herbie, the empty string in the line below was the key part missing!

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