I am having troubles with a constructed lists. I have three "variables"
UserID, Car and Color. Each user can own 1 up to 3 cars as in the table below.
UserID Car1 Color1 Car2 Color2 Car3 Color3
Susan Ferrari Red Opel Blue
Mark Nissan Black
John Subaru Red Lamborghini Orange Maserati Grey
I have created three lists:
The first one (CarList) has [%Car1%], [%Car2%] and [%Car3%] as entries.
The second one (ColorList) has [%Color1%], [%Color2%] and [%Color3%] as entries.
The third one "CarColorList" has
"[%Car1%] ; <i>[%Color1%]</i>" ;
"[%Car2%] ; <i>[%Color2%]</i>";
"[%Car3%] ; <i>[%Color3%]</i>"
as entries.
I would like to create a construct list whose parent list is "CarColorList" which shows 1 car if the user has one car, 2 cars if he has 2 cars and 3 cars if 3 cars are owned.
As an example, if the user is Mark, only "[%Car1%];<i>[%Color1%]</i>" should appear, while if the owner is John "[%Car1%];<i>[%Color1%]</i> [%Car2%];<i>[%Color2%]</i> and [%Car3%];<i>[%Color3%]</i> should appear.
I have wrote the following unverified pearl code
Begin Unverified Perl
my %Values = ();
my $ i = 0;
for($i = 1; $i <= LISTLENGTH("CarColorList"); $i++)
{
if(!exists $Values{(LISTLABEL(" CarColorList ", $i))} && (LISTLABEL("CarColorList", $i) ne ";"))
{
$Values{uc(LISTLABEL("CarList1", $i))} eq LISTLABEL("CarColorList", $i);
ADD(" CarColorList", $i);
}
}
End Unverified
However, the code has some issues since when the user owns 2 cars it shows 3 entries with the last one being just a ";". If, instead, the user owns 1 car only the color appears.
Thanks a lot in advance!