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?
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
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
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