Problem with "getResult" in a macro

Dear forum mates,

I “stole” a macro from a forum that subtracts background from all slices of an image stack based on a ROI selected by the user. The same ROI is used for all slices. For each slice the intensity of the ROI is measured and based on it a value is subtracted. I had to change the original macro a little bit (I do not remember what I had to do to it), but after it worked fine. Several months later (now) I wanted to use it again. But it does not work now. It returns an error message:

"no results found in line 12
bgmean=getResult(“Mean”,(i-1 <)>); "

Line 12 is this:
I tried to replace (i-1) by numbers (0, 1 or 2) just to see if it works then, but not.
I copy the whole code below:

macro “BG [F12]” {
currentTitle = getTitle();
run(“Set Measurements…”, " mean standard redirect=None decimal=0"); scaling=3");
//scaling=getNumber(“Enter Scaling factor”,3)
if (nSlices>1){
// setSlice(1);
run(“Plot Z-axis Profile”); run(“Close”);
for (i=1; i<=nSlices; i++){
run(“Set Slice…”, “slice=”+i);
run(“Select All”);
run(“Subtract…”, “slice value=”+bgTotal);}
if (nSlices==1) {run(“Measure”);
run(“Select All”);
run(“Subtract…”, “value=”+bgTotal);
run(“Select None”);
//showMessage(“StDev=”+bgStDev+ " Mean BG = “+bgmean);
run(“Set Measurements…”, " mean redirect=None decimal=0”);
run(“Select None”);

Does anyone have any idea?

Kind Regards

Good day Ferenc,

please tell us if there is a Results table open when you run the macro.

If there is no Results table showing a “Mean” column, then you can’t get values from it.

Please be more specific


No, there is no results table open. I do not even know what resilts table the code refers to. The only measurement I see is the z-axis profile. I wanted to make the macro to print the results table to see it, but I did not know how to do it.

Sorry, I don’t understand your reply:

With this code line

bgmean = getResult("Mean",(i-1));

you try to get a value from the “Mean”-column of a Results table. Of course, there must be a Results table with such a column, otherwise you get an error message.

I don’t believe that the macro ever has run correctly.



Dear Herbie,

I see what you mean, and it sounds correct. However, I am pretty sure that I used this very macro earlier. It is in my macro folder, where I store and use macros. And I found another macro in a forum, that is almost the same as mine and works for others, but returns the same error message for me as my macro (no results in the line begining with bgresults=getresults…). It is here (I hope, it is not against the rules to link here pages from other forums):



please accept that I’m not willing to understand other people’s code.

there is no results table open.

If this is true, then your macro won’t work. Please try to understand this fact.

I have no idea how you use the posted macro code and I don’t have written it.

Good luck


Yes, I see. I didn’t want to argue. Anyway, thank you for your time :slight_smile:

Kind regards