# Incrementing a tag

**URL:** <https://forum.inductiveautomation.com/t/incrementing-a-tag/3598>\
**Category:** Ignition\
**Created:** [November 14, 2011, 4:29pm UTC](https://forum.inductiveautomation.com/t/incrementing-a-tag/3598 "2011-11-14T16:29:49Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryanbeno](https://avatars.discourse-cdn.com/v4/letter/r/8baadc/32.png) [@ryanbeno](https://forum.inductiveautomation.com/u/ryanbeno)\
**Post date:** [November 14, 2011, 4:29pm UTC](https://forum.inductiveautomation.com/t/incrementing-a-tag/3598/1 "2011-11-14T16:29:49Z")

</div>

I am looking to create a tag that increments automatically by one. I would like to do so so I can simulate tank behaviors to make it look like it is filling a tank. I have seen various posts of creating a tag with a client timer. Is this the only way to create a tag to “increment” to a value that I can use to behave this way? Any suggesstions would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![Greg.Buehler](https://avatars.discourse-cdn.com/v4/letter/g/ecc23a/32.png) [@Greg.Buehler](https://forum.inductiveautomation.com/u/Greg.Buehler)\
**Post date:** [November 14, 2011, 4:39pm UTC](https://forum.inductiveautomation.com/t/incrementing-a-tag/3598/2 "2011-11-14T16:39:29Z")

</div>

If you load the Simulation driver, there are several ramp tags that would fit your needs.

Otherwise you can make a gateway script that increments a DB tag.

```auto
tag = "path.to.tag"
value = system.getTagValue(tag)
value = value + 1
system.tag.writeToTag(tag, value)
```

---

<div class="post-metadata">

**Author:** ![ryanbeno](https://avatars.discourse-cdn.com/v4/letter/r/8baadc/32.png) [@ryanbeno](https://forum.inductiveautomation.com/u/ryanbeno)\
**Post date:** [November 14, 2011, 5:11pm UTC](https://forum.inductiveautomation.com/t/incrementing-a-tag/3598/3 "2011-11-14T17:11:29Z")

</div>

I was going to use a simulation driver. However I want to be able to manipulate the data that the counter is using. For example when it hits a certain level I would like to be able to stop the bit from counting and reset it

---

<div class="post-metadata">

**Author:** ![Greg.Buehler](https://avatars.discourse-cdn.com/v4/letter/g/ecc23a/32.png) [@Greg.Buehler](https://forum.inductiveautomation.com/u/Greg.Buehler)\
**Post date:** [November 14, 2011, 5:41pm UTC](https://forum.inductiveautomation.com/t/incrementing-a-tag/3598/4 "2011-11-14T17:41:22Z")

</div>

Do you just mean restarting the ramp, or actually setting the ramp to 0 and stopping the increment?

```auto
resetpoint = 1000
tag = "path.to.tag"

value = system.getTagValue(tag)
value = value + 1
if value >= resetpoint:
    value = 0

system.tag.writeToTag(tag, value)
```

```auto
enabletag = "path.to.enabletag" 
valuetag = "path.to.valuetag"
resetpoint = 1000

enabled = system.getTagValue(enabletag)
value = system.getTagValue(valuetag)
value = value + 1
if (value >= resetpoint) and (enabletag > 0):
    system.tag.writeToTag(enabletag, 0)    
    value = 0

system.tag.writeToTag(tag, value)
```

---

<div class="post-metadata">

**Author:** ![ryanbeno](https://avatars.discourse-cdn.com/v4/letter/r/8baadc/32.png) [@ryanbeno](https://forum.inductiveautomation.com/u/ryanbeno)\
**Post date:** [November 14, 2011, 6:34pm UTC](https://forum.inductiveautomation.com/t/incrementing-a-tag/3598/5 "2011-11-14T18:34:13Z")

</div>

I’m looking to actually reset the ramp to 0 and stop the increment

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [November 14, 2011, 6:47pm UTC](https://forum.inductiveautomation.com/t/incrementing-a-tag/3598/6 "2011-11-14T18:47:02Z")

</div>

You cannot alter any of the ramp simulator tags since they are read-only.

---

<div class="post-metadata">

**Author:** ![ryanbeno](https://avatars.discourse-cdn.com/v4/letter/r/8baadc/32.png) [@ryanbeno](https://forum.inductiveautomation.com/u/ryanbeno)\
**Post date:** [November 14, 2011, 6:55pm UTC](https://forum.inductiveautomation.com/t/incrementing-a-tag/3598/7 "2011-11-14T18:55:17Z")

</div>

I thought they were read-only. Are there any other ideas of what I could try? I was going to use a DB tag and attempt to increment it with a script and then reset to 0 when a certain number is reached. Does anyone have any other thoughts on what may work here?

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [November 14, 2011, 9:03pm UTC](https://forum.inductiveautomation.com/t/incrementing-a-tag/3598/8 "2011-11-14T21:03:17Z")

</div>

Four ways come to mind for what you are doing.

Client Timer: quick and dirty, and lets you adjust speed and upper bounds on the fly. On the other hand, the client must be running (or the designer in preview mode) to work.

Client script: use a script like the one Mr. Buehler posted earlier. The client must actually be running for these to work.

Gateway script: same as a client script, but is always running on the gateway. Remember that any timing changes to the script must have the project saved for them to work.

Transaction group: you can do this with a transaction group running at whatever rate you wish. Not really an option on Panel Edition.
