Posted by
Wayne Rasband-2 on
Oct 24, 2018; 8:36pm
URL: http://imagej.273.s1.nabble.com/Strange-behavior-of-Dialog-addMessage-vs-Dialog-addNumber-tp5021331p5021342.html
> 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