Strange behavior of Dialog.addMessage vs Dialog.addNumber

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Strange behavior of Dialog.addMessage vs Dialog.addNumber

Philippe CARL
Dear all,

Please consider the following small macro :

                ParameterValues = newArray(0, 1, 2, 3);

                j = 0;

                Dialog.create   ("Create Settings");

                Dialog.addNumber("Parameter 0", ParameterValues[j++]);
print("a", j);

                Dialog.addNumber("Parameter 1", ParameterValues[j++]);
print("b", j);

                Dialog.addNumber("Parameter 2", ParameterValues[j++]);
print("c", j);

                Dialog.show();

Which is working as I would expect it, with the parameter j incremented by a
value of one at each j++ invocation.

But if I replace the 5th line, i.e. the line:

                Dialog.addNumber("Parameter 1", ParameterValues[j++]);
print("b", j);

by the line:

                Dialog.addMessage("Parameter 1    " + ParameterValues[j++]);
print("b", j);

the value j following the Dialog.addMessage gets incremented not by a value
of 1 but of 2.

Is this a bug or is there an issue in the way I’m trying to write my code?

I thank you very much in advance for your lightings about this question.

My best regards,

Philippe

 

Philippe CARL

Laboratoire de Bioimagerie et Pathologies

UMR 7021 CNRS - Université de Strasbourg

Faculté de Pharmacie

74 route du Rhin

67401 ILLKIRCH

Tel : +33(0)3 68 85 41 84


--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Strange behavior of Dialog.addMessage vs Dialog.addNumber

Wayne Rasband-2
> On Oct 23, 2018, at 10:51 AM, Philippe CARL <[hidden email]> wrote:
>
> Dear all,
>
> Please consider the following small macro :

Thanks to Michael Schmid, the latest ImageJ daily build (1.52i14) fixes a bug that caused the macro interpreter, with statements like

   str = "" + <numericExpression>;

to evaluate the numeric expression twice, causing the index to be incremented twice. Here his small macro that reproduces the problem:

  values = newArray(0, 1, 2);
  j = 0;
  str = "" + values[j++];
  print("Actual: str="+str+", j="+j);
  print("Expected: str=0, j=1”);

-wayne


>                ParameterValues = newArray(0, 1, 2, 3);
>
>                j = 0;
>
>                Dialog.create   ("Create Settings");
>
>                Dialog.addNumber("Parameter 0", ParameterValues[j++]);
> print("a", j);
>
>                Dialog.addNumber("Parameter 1", ParameterValues[j++]);
> print("b", j);
>
>                Dialog.addNumber("Parameter 2", ParameterValues[j++]);
> print("c", j);
>
>                Dialog.show();
>
> Which is working as I would expect it, with the parameter j incremented by a
> value of one at each j++ invocation.
>
> But if I replace the 5th line, i.e. the line:
>
>                Dialog.addNumber("Parameter 1", ParameterValues[j++]);
> print("b", j);
>
> by the line:
>
>                Dialog.addMessage("Parameter 1    " + ParameterValues[j++]);
> print("b", j);
>
> the value j following the Dialog.addMessage gets incremented not by a value
> of 1 but of 2.
>
> Is this a bug or is there an issue in the way I’m trying to write my code?
>
> I thank you very much in advance for your lightings about this question.
>
> My best regards,
>
> Philippe
>

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