**NOTE:**

This tips 'n trick thread heavily uses the Modulo operator (i.e. %), otherwise known as Remainder Division. It's important to understand how this operator works before continuing.

First we're going to create some variables that we are going to use later on.

Code: Select all

```
[Variables]
MaxNumber=30
Pause=1
Reset=1
```

Code: Select all

```
[cCounter]
Measure=Calc
Formula=cCounter+1
```

**Note:**When naming your counter always remember that there is a built in Variable/Function named Counter so yours should be named something else.

**Making the counter reset at a given value**

Having it reset after a given value is easy and is accomplished the same way as if you were using the Counter variable.

Code: Select all

```
[cCounter]
Measure=Calc
Formula=(cCounter+1)%(#MaxNumber#+1)
```

If you want your counter to reset to one instead of zero we just need to move things around a bit.

Code: Select all

```
[cCounter]
Measure=Calc
Formula=cCounter%#MaxNumber#+1
```

**Resetting a counter via Mouse Actions**

How about having it reset to zero when we click on the skin.

Code: Select all

```
[Rainmeter]
LeftMouseUpAction=!SetVariable Reset 0
[cCounter]
Measure=Calc
Formula=(cCounter+1)*#Reset#
IfBelowValue=1
IfBelowAction=!SetVariable Reset 1
DynamicVariables=1
```

Ghost points out that if you want to reset with MouseOver there is a much nicer way without using a variable.

Code: Select all

```
[Rainmeter]
MouseOverAction=!DisableMeasure cCounter
MouseLeaveAction=!EnableMeasure cCounter
[cCounter]
Measure=Calc
Formula=cCounter+1
```

**Note:**This method only works if the counter is disabled for at least one update cycle.

Now we can combine a couple methods of resetting to have the counter count up, reset, and wait for us to tell it restart again.

Code: Select all

```
[cCounter]
Measure=Calc
Formula=cCounter+1
IfEqualValue=#MaxNumber#
IfEqualAction=!DisableMeasure #CURRENTSECTION#
```

**Pausing a counter**

Lets pause the counter when you mouse-over the skin.

Code: Select all

```
[Rainmeter]
MouseOverAction=!SetVariable Pause 0
MouseLeaveAction=!SetVariable Pause 1
[cCounter]
Measure=Calc
Formula=cCounter+#Pause#
DynamicVariables=1
```

We can also have the counter stop counting at a certain value and stay there.

Code: Select all

```
[cCounter]
Measure=Calc
Formula=cCounter+(cCounter<#MaxNumber#)
```

**Triggering Actions with a Counter**

Code: Select all

```
[cCounter]
Measure=Calc
Formula=cCounter+1
IfAboveValue=#MaxNumber#
IfAboveAction=[!DisableMeasure #CURRENTSECTION#]["Some Action"]
```

We can use the built in Counter function/variable to accomplish the same thing. Please note that Counter returns the number of updates since the skin was initially loaded and only returns to zero when Rainmeter is loaded or a !RefreshApp bang is used.

Code: Select all

```
[cCounter]
Measure=Calc
Formula=Counter
IfAboveValue=#MaxNumber#
IfAboveAction=[!DisableMeasure #CURRENTSECTION#]["Some Action"]
```

**Note:**To execute a set of commands when the skin is loaded or refreshed, without using a counter, use OnRefreshAction=!SomeAction in the [Rainmeter] section of the skin.

**Bonus Lesson: Making a counter that counts down, not up**

Code: Select all

```
[cCounter]
Measure=Calc
Formula=(cCounter-1+(#MaxNumber#+1))%(#MaxNumber#+1)
```