Login  Register

Re: Dialog.addChoice with Variables / Variables in an Array?

Posted by ctrueden on Jul 30, 2014; 3:12pm
URL: http://imagej.273.s1.nabble.com/Dialog-addChoice-with-Variables-Variables-in-an-Array-tp5008965p5008978.html

Hi Ray,

> I'd like the user's choice in the dialog to translate into the string
> of the respective variable, i.e. choosing "Green" or "Red" in the
> dialog is supposed to print "File1" or "File2"

How about this?

--snip--
files = newArray("File1", "File2", "Shazam");
choices = newArray("Green", "Red", "Blue");
Dialog.create("Test");
Dialog.addChoice("Slide 1", choices);
Dialog.show();
result = Dialog.getChoice();
for (i=0; i<choices.length; i++) {
if (result == choices[i]) {
file = files[i];
break;
 }
}
print(file);
--snap--

-Curtis


On Wed, Jul 30, 2014 at 10:04 AM, Gabriel Landini <[hidden email]>
wrote:

> On Wednesday 30 Jul 2014 07:54:49 you wrote:
> > Gabriel Landini wrote
> >
> > > Green is a variable, "Green" is a string, so change the above to:
> > >
> > > choices = newArray(Green, Red);
> >
> > Thanks for your reply, but I already tried that, and when I do so the
> > choices in the dialog box are both shown as "NaN", and I also recieve
> "NaN"
> > from the print function.
>
> So strange. Your modified example works fine here.
>
> Green = "File1";
> Red = "File2";
> choices = newArray(Green, Red);
> Dialog.create("Test");
> Dialog.addChoice("Slide 1", choices);
> Dialog.show();
> Result = Dialog.getChoice();
> print(Result);
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

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