Page 1 of 1

List of Lists

Posted: April 11th, 2024, 9:30 am
by slwendo
eg. list string tinyList1;
list string tinyList2;
list string tinyList3;

list bigList = tinyList1, tinyList2, tinyList3;

Re: List of Lists

Posted: April 11th, 2024, 11:16 am
by justinlakier
Hello,

A List is one-dimensional and can hold either numeric or string values. It cannot contain other lists. For this, you may want to use a multidimensional Array to hold your list values. In the example below, the array has 2 dimensions- the first dimension for the number of lists to keep track of, and the second dimension for the length of the lists. A do loop then takes all values from these lists into the array. Arrays in CSPro need constant dimensions, so this assumes that you have determined the number and length of lists ahead of time, and that the length of the lists can be made to match. If this is too rigid for your application, you may want to look into a multidimensional HashMap object instead
array string myArrayOfLists(3, 6);
list string firstList = "1","2","3","4","5","6";
list string secondList = "6","5","4","3","2","1";
list string thirdList = "1","1","1","1","1","1";

do numeric i=1 until i>6
   
myArrayOfLists(1,i) = firstList(i);
    myArrayOfLists(2,i) = secondList(i);
    myArrayOfLists(3,i) = thirdList(i);
enddo;

showarray(myArrayOfLists);
Hope this helps,
Justin

Re: List of Lists

Posted: April 12th, 2024, 2:51 am
by slwendo
Thanks!