# List Problem

I have 2 lists

set ProductList to {“A”, “B”, “C”, “D”, “E”, “F”}
set HierarchyList to {“‘A01’,‘A07’”, “‘A02’,‘A07’”, “‘A03’,‘A07’”, “‘A09’,‘A07’,‘A11’”, “‘A09’,‘A07’,‘A11’”, “‘A10’,‘A07’”}

If I choose an item in ProductList (f.e. A)
I want to get the answer “‘A01’,‘A07’”

How do I have to write the code for this function?

Hi,

something like this, it calculates the list index from the numeric value of the letter

``````
set ProductList to {"A", "B", "C", "D", "E", "F"}
set HierarchyList to {"'A01','A07'", "'A02','A07'", "'A03','A07'", "'A09','A07','A11'", "'A09','A07','A11'", "'A10','A07'"}

set chosenItem to choose from list ProductList
if chosenItem is false then return
set idx to (id of item 1 of chosenItem) - 64
set theResult to item idx of HierarchyList

``````

I still can’t see what -64 soes.

If I select
d I get “‘A09’,‘A07’,‘A11’”.
Is this right?

Oh I see. Double quotes.
Interesting.

In the ASCII/UTF8 table the character A is represented by the decimal value 65, character B by 66 and so on.
To calculate the 1-based index of the list(s) you have to subtract 64

Thank you!!

it works fine, but in a next step the first list won’t be A, B, C, D but names or codes.

this script doesn’t work with codes in the first list.

then you need a repeat loop to get the list index

``````
set ProductList to {"Alpha", "Beta", "Gamma", "Delta", "Epsilon", "Zeta"}
set HierarchyList to {"'A01','A07'", "'A02','A07'", "'A03','A07'", "'A09','A07','A11'", "'A09','A07','A11'", "'A10','A07'"}

set chosenItem to choose from list ProductList
if chosenItem is false then return
set productListItem to item 1 of chosenItem
repeat with idx from 1 to count ProductList
if productListItem is item idx of ProductList then exit repeat
end repeat

set theResult to item idx of HierarchyList

``````

Thanks… this works!!!