Nice, it works :) The function:
private int WrapValue( int val, int lowerBound, int upperBound ) {
int result = lowerBound + ( val - lowerBound ) % ( upperBound - lowerBound );
if( result < lowerBound ) {
result += ( upperBound - lowerBound );
}
return result;
}
I tried it with all different bounds and values and it works great. Thanks a ton :)