I assume you are either defining iGroupNum as integer or allowing it to
be defined automatically as integer.
Functions like Right, etc, work on strings, and might get in trouble
with integers.
Put an explicit definition in for iGroupNum as String (or perhaps call
it sGroupNum for correctness). Alternatively, use Mod and Int functions
to act directly on the integer values instead.