Your method works fine. The problem lies in the fact that the input you get from
y = Application.XSIInputbox ('Which list?','Search List')
will be a string. So y
is a string and not a list. The same applies to x
of course but that doesn't give an issue because your lists contain only strings.
What happens is your function call actually looks like this (example)
findguy('l1', 'Zemo')
and then on this line
if where[i] == inputguy:
it will compare the characters of l1
, being l
and 1
to inputguy
. Of course that keeps being false so you get "not here" as output.
What you want is your function call to look like this instead
findguy(l1, 'Zemo')
This can be achieved by doing something like this:
y = Application.XSIInputbox ('Which list?','Search List')
if y == "l1":
y = l1
elif y == "l2":
y = l2
This simply 'picks' a list based on your input and passes that to findguy
. In your situation this would be an O.K. solution but if your code was only an example and your actual code has more lists, or will have in the future you should look for a better solution. A suggestion would be to store your guys in a dictionary instead:
guys = {'l1': ['Taskmaster', 'Red Skull', 'Zemo'], 'l2': ['Capt. America', 'Iron Man', 'Thor']}
Then you can process your input with
x = Application.XSIInputbox ("Who are you looking for?","find character")
y = Application.XSIInputbox ('Which list?','Search List')
findguy (guys[y], x)
This works because the dictionary's keys are strings.