Strange variable type for arrays filled from a dialog in macro language ?

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

Strange variable type for arrays filled from a dialog in macro language ?

lechristophe
Hi,

Please consider the following macro snippet:

Dialog.create("Dialog");
Dialog.addString("string 1", "1");
Dialog.addString("string 2", "2");
Dialog.addString("string 3", "No");
Dialog.show();
TEXT1=Dialog.getString();
TEXT2=Dialog.getString();
TEXT3=Dialog.getString();

ARRAY=newArray("1", "2", "No");
if (ARRAY[2]=="No") print("success");

ARRAYDIALOG=newArray(TEXT1, TEXT2, TEXT3);
if (ARRAYDIALOG[2]=="No") print("success");



ARRAY and ARRAYDIALOG should be exactly the same, containing three strings
"1", "2" and "No". ARRAY is directly defined, whereas ARRAYDIALOG is defined
via a dialog box that gets the user to enter strings. Just run the macro and
click "OK" in the Dialog, leaving the default text values. The test on
ARRAY[2] prints "success", but the second test for ARRAYDIALOG[2]=="No"
unexpectedly triggers the error "Number or numeric function expected".

I think this is a bug that has to do with the types of variables returned by
Dialog.getString(). Or am I confused ?

Christophe
Reply | Threaded
Open this post in threaded view
|

Re: Strange variable type for arrays filled from a dialog in macro language ?

Herbie-6
Christophe,

try

ARRAYDIALOG=newArray( "" + TEXT1, TEXT2, TEXT3);


>Hi,
>
>Please consider the following macro snippet:
>
>Dialog.create("Dialog");
>Dialog.addString("string 1", "1");
>Dialog.addString("string 2", "2");
>Dialog.addString("string 3", "No");
>Dialog.show();
>TEXT1=Dialog.getString();
>TEXT2=Dialog.getString();
>TEXT3=Dialog.getString();
>
>ARRAY=newArray("1", "2", "No");
>if (ARRAY[2]=="No") print("success");
>
>ARRAYDIALOG=newArray(TEXT1, TEXT2, TEXT3);
>if (ARRAYDIALOG[2]=="No") print("success");
>
>
>
>ARRAY and ARRAYDIALOG should be exactly the same, containing three strings
>"1", "2" and "No". ARRAY is directly defined, whereas ARRAYDIALOG is defined
>via a dialog box that gets the user to enter strings. Just run the macro and
>click "OK" in the Dialog, leaving the default text values. The test on
>ARRAY[2] prints "success", but the second test for ARRAYDIALOG[2]=="No"
>unexpectedly triggers the error "Number or numeric function expected".
>
>I think this is a bug that has to do with the types of variables returned by
>Dialog.getString(). Or am I confused ?
>
>Christophe

Best
                  Herbie

          ------------------------
          <http://www.gluender.de>
Reply | Threaded
Open this post in threaded view
|

Re: Strange variable type for arrays filled from a dialog in macro language ?

Rasband, Wayne (NIH/NIMH) [E]
In reply to this post by lechristophe
On Sep 28, 2011, at 7:30 AM, Christophe Leterrier wrote:

> Hi,
>
> Please consider the following macro snippet:
>
> Dialog.create("Dialog");
> Dialog.addString("string 1", "1");
> Dialog.addString("string 2", "2");
> Dialog.addString("string 3", "No");
> Dialog.show();
> TEXT1=Dialog.getString();
> TEXT2=Dialog.getString();
> TEXT3=Dialog.getString();
>
> ARRAY=newArray("1", "2", "No");
> if (ARRAY[2]=="No") print("success");
>
> ARRAYDIALOG=newArray(TEXT1, TEXT2, TEXT3);
> if (ARRAYDIALOG[2]=="No") print("success");
>
> ARRAY and ARRAYDIALOG should be exactly the same, containing three strings
> "1", "2" and "No". ARRAY is directly defined, whereas ARRAYDIALOG is defined
> via a dialog box that gets the user to enter strings. Just run the macro and
> click "OK" in the Dialog, leaving the default text values. The test on
> ARRAY[2] prints "success", but the second test for ARRAYDIALOG[2]=="No"
> unexpectedly triggers the error "Number or numeric function expected".
>
> I think this is a bug that has to do with the types of variables returned by
> Dialog.getString(). Or am I confused ?

It is a bug in the newArray() function that is fixed in the ImageJ 1.45q daily build.

-wayne