Encoder Doesn't Reset to Zero

We have a strange programming bug that we’re a bit stuck on. We have an encoder on a mechanism that we want to reset every time a limit switch is depressed. However, when we depress the limit switch, weird things happen. The printed value of the count from encoder.Get() either just adds a zero to the end of the number or replaces the first digit with zero. For example, numbers like 215 and 217 turn to 015 and 017. Once we break 1000, the number just changes from something like 1300 to 01300, and then begins counting much faster.

We have no idea why this happens or how to fix it. Got any ideas?

Update: We changed the code so that the limit switch reset a drivetrain encoder instead of the mechanism encoder and it worked perfectly. I’ll see if we can get code up. I have no idea why this would work for one encoder but not the other.

Update 2: We ruled out a hardware problem by plugging the mechanism encoder into the DT encoder port, it resets in that port fine.

How are you displaying the current encoder value?
This sounds like a common display bug where the line isn’t cleared before printing a new number.
If an output contains ‘217’ and ‘0’ is printed without clearing the line, then you’d get ‘017’.
There are a few ways to fix this (if it is the problem): Clear the line before writing a number, or append spaces to the number that you are printing.
By appending spaces before printing, ‘217’ and '0 ’ would be seen as ‘0’ instead of ‘017’