This should serve as a good example to get you started. As always, please feel free to post any comments, issues, and/or suggestions you may have concerning this macro.
Example Output
MACRO: How to Use a Counter [Example]
#### DOWNLOAD:
<a class="attachment" href="/uploads/default/original/3X/5/5/55417b8b2628112929bf26e976c6ff7adc01ad31.kmmacros">How to Use a Counter [Example].kmmacros</a> (4.7 KB)
**Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.**
---
![image|617x998](upload://1FLUVAdNnCJBXsEHFMyea9gtChq.jpg)
---
**NOTE:** The `+ 1` shows up in red because the variable "Local__Counter" is a _local_ variable, and is not defined until execution time.
![image|543x170](upload://z1RFB8qzNFR0EBfGjQ3sBm7gBEr.png)
@peternlewis, this display behavior does not make any sense to me, and misleads us.
You should not show any "errors" in red related to _Local_ or _Instance_ variables.
Please consider making a change to KM.
I'm still having a problem understanding the counter.
Just a little background: My use of the counter is to attach the counter number to a file name when the file is saved. The original file is an email that I'm exporting as a pdf and then naming before its saved.
Results
I did some experimenting with the counter as a result of your macro and this resulted in getting the macro "seeded" with the number 1. However none of my experiments worked so I reverted to using simply:
Set Variable Count
to Count +1
As a result of seeding the macro with a previous value (1) when I ran the macro a second time it worked as expected and added the number 2 to the filename.
This suggests to me that my lack of understanding has to do with the initial condition. Meaning that the first time through the action if there is no history of a value the calculation cannot be completed.
I can't set the initial value to zero in the macro since as a result it would be reset each time the macro is executed.
So I'm guessing that I don't understand how to configure this particular function.
Anytime I use a counter like this I need to run a separate macro to set the value.
Once that is done I can use the counter variable in the intended macro.
I'm seeing that was probably the intention in the example macro from @JMichaelTX but it appeared to me that they were all one macro.
But you do need to initialize the counter before you increment it.
You can do this within the same macro, as I did in my example.
If you want a counter that increases over multiple executions of the same macro, or over executions of multiple macros, then you need to use a KM GlobalVariable.
I would usually do something like this to ensure the variable is initialized.
Put this at the very top of your macro(s) -- all macros that use the counter.
Then, later in the macro:
I use the KM Variable prefix of "DND" for Do Not Delete, to make clear when I'm in the Preferences Variable Panel to NOT delete it.
I also use the two underscores so that the "DND" prefix does NOT show in Prompt for User input.
This macro is amazing! I'd love to know how can I modify this counter. What I'm gonna do is a little complicated, but I'll make it simple to understand so someone can help me.
Let say I'm going to put these numbers in Numbers' cells one by one and each time it presses the return key.
Hey Chris! Thanks for being here trying to help me.
I tried to describe my problem as much as I could, but please let me know if something doesn't make sence.
Hey Chris! Good news! I've just made the macro I needed and it works very well.
I have to thank you because if you didn't message me I wouldn't try to make this myself.
I made it and I'm super happy.
Thank you