Login  Register

getting array index of a string

Posted by arnim.jenett on Nov 15, 2007; 10:00pm
URL: http://imagej.273.s1.nabble.com/getting-array-index-of-a-string-tp3697992.html

I have to browse pictures of 96 well plates. These are named by their position on the plate (A01, A02, ..., H12). So I wrote a macro with a Dialog with a couple of arrays in which the user can select the coordinates and get the images. For browsing from one location to the next I simply increase the column index and reset it to 0 when I reach 12. But how can I go to the next row? I would like to get the index of the current string in the 'row'-array. Is there a way to do this? Below I pasted a shortend sample script with three exclamation marks at the point where I am stuck:

row=newArray("A", "B", "C", "D", "E", "F", "G", "H");
column=newArray("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12");
if (File.exists(getDirectory("macros")+"test.txt")) {
                liste=getDirectory("macros")+"test.txt";
                string=File.openAsString(liste);
                liste=split(string, " ");
                R=liste[0]; //row
                c=liste[1]; //column
                nc=parseInt(liste[2]); //next column
                if (nc == 1){
                        c=parseInt(liste[1]);
                        if (c==12) {
                                c=0;
//!!! R=R+1; //how can I achieve this?
//this is rather bulky but the best I have. an array index would help here. any better idea?
                                if (R=="A") { R="B";}
                                else if (R=="B") { R="C";}
                                else if (R=="C") { R="D";}
                                else if (R=="D") { R="E";}
                                else if (R=="E") { R="F";}
                                else if (R=="F") { R="G";}
                                else if (R=="G") { R="H";}
                                else if (R=="H") { R="A";}
//
                        } else {
                                c=column[c];
                        }
                }
} else {
                R=row[0];
                c=column[0];
                nc=0;
}
        Dialog.create("Data Loader");
        Dialog.addChoice("row:", row, R);
        Dialog.addChoice("column:", column, c);
        Dialog.addCheckbox("next column", nc);
        Dialog.show();
        row=Dialog.getChoice();
        column=Dialog.getChoice();
        nextImage=Dialog.getCheckbox();
        print("\\Clear");
        print(row+" "+column+" "+ nextImage);
        selectWindow("Log");
        saveAs("Text", getDirectory("macros")+"test.txt");