Cycle Variable Through Value List

I want to use one variable as a value list and cycle another variable through those values.

EX.
Set VALUES variable to be "AFEH".
And then iterate the variable VALUE through the values A,F,E,H,A,F,E,H...

Thanks in advance!

Hey Mike,

Probably the simplest method for that task is something like this.

-Chris


Iterate Through Values Example v1.00.kmmacros (8.3 KB)

@ccstone' s is a good solution if you want to loop through each value in the cycle within a macro run.

For a slightly different context, in which you want a variable to take on the next cycle value on each separate macro run, you could take advantage of the indexed %JSONValue% tag, which gives you lists:

  • containing their own length in position 0
  • and offering 1-based indexed access to each value.

allowing for expressions like:

image

So, for a macro which increments its cycle index value on each run, we might write things like:

Next value in a cycle.kmmacros (22.7 KB)

1 Like

PS if you need to define run-time conversions of the pattern:

AFEH -> ["A","F","E","H"]

you can write things like:

Plain string to comma delimited JSON list format.kmmacros (19.5 KB)

-->

1 Like

Yes, that is what I meant. The next value each time the macro is run. Awesome!