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 |
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> |
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 |
Free forum by Nabble | Edit this page |