How to create and call variable() as function

I have a list of zip codes I want to use in my script.

I want to call something like zipcodes(1) and obtain first zip code from predefined list, call zipcodes(7) and obtain 7th zip code from the list.

How do I create a variable %zipcode% that I can use like that?

Thank you

If they’re numeric only, with no dashes, etc, then you can use Set Variable to Text to separating the zip codes with a comma (and optional space), then you can refer to them using Set Variable to Calculation with an index, like “MyZipCodes[2]”.

Otherwise, you could use Set Variable to Text putting each zip code on a new line. Then you could use a “For Each” action and a counter to loop through until you get to the one you want.

Or you could do it via AppleScript or JXA.

Let me know if you need further explanation.

Without more details, I'm having to make a bunch of assumptions here . . .

When you say "script" do you mean a real script like AppleScript or JXA, or a KM Macro?
Assuming a real script:

2016-09-20 16:37 CT (Tue)

Just posted an example macro/script:

Just updated my post.

Hi @DanThomas!

Thank you for you response.

How do I call MyZipCodes[2] using a variable instead of [2] ?

I tried this:

and it worked, however, when I tried to use Variable instead of [2] (in your example, it didn't work.

Thank you

When you're using a Calculation field, you never specify %Variable%, you just use the name of the variable. So the "to:" field would be:

ZipCodes[linenumber]

Thank you @DanThomas

1 Like