Login  Register

Re: Array of strings- a macro question

Posted by George Patterson on Aug 04, 2015; 11:45pm
URL: http://imagej.273.s1.nabble.com/Array-of-strings-a-macro-question-tp5013893p5013894.html

Guy,
I think you need to move the following lines outside the loop before the "for
(j=0; j<MyString; j++)".
StringArray=newArray(MyString);
FolderListPath=newArray(MyString);
These are making a new array each time through the for loop and you end up
with only the last one containing the last string.
I think you just need to create those arrays one time for that part of the
code at least.
Best,
George

On Tue, Aug 4, 2015 at 5:01 PM, GuyM <[hidden email]>
wrote:

> Hello everyone,
> I am writing a macro that will accept from the user string arguments, in
> order to sort files in one folder into different subfolders, based on
> differences in string occurrences in these file names (i.e.
> "...RedChannel..." vs "...BlueChannel..."). But I require some assistance
> with the following (displayed are only pieces of the code):
>
> The user inputs the number of desired inputs/strings (manifested here
> below as "myString"):
>     for (j=0; j<MyString; j++) {
>     Dialog.addString("String "+j, title);
>     }
>     Dialog.show();
>
>
> and then inputs the same number of strings to serve as future substring
> regexp and to construct the subfolders names:
>     for (j=0; j<MyString; j++) {
>     CurrentString= Dialog.getString();
>     StringArray=newArray(MyString);
>     FolderListPath=newArray(MyString);
>     StringArray[j]=CurrentString;
>     CurrentPath = path +CurrentString+ File.separator;
>     FolderListPath[j]=CurrentPath;
>     File.makeDirectory(CurrentPath);
>     }
>
>
> But I noticed something strange: as the loop (the second one) proceeds,
> the arguments are passed ok one by one into the arrays. Once the loop
> terminates, the last row of the arrays are ok, but the rows above it are
> filled with zeros! I checked, and this also happens when numeric variables
> are being input instead of strings.
>
> Any idea?
> Thanks a lot in advance and all the best!
> Guy
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

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