the links i provided show typical looooong nav style functions.
using .net classes i developed a much smaller, cooler function:
// loc. vars
// DocNo : Code-20
---------------------------------
OnRun()
DocNo := DecStr('ABC00010'); // typical document no.
MESSAGE(DocNo);
---------------------------------
// loc. vars
Prefix Text
NoString Text
Number Integer
Regex DotNet System.Text.RegularExpressions.Regex.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
DotNetInt DotNet System.Int32.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
PadLength Integer
---------------------------------
DecStr(DocNo : Code[20]) : Code[20]
Prefix := Regex.Replace(DocNo,'\d+','');
NoString := Regex.Match(DocNo,'\d+').Value;
Number := DotNetInt.Parse(NoString); // instead of using Evaluate
IF Number > 0 THEN BEGIN
Number := Number - 1;
PadLength := STRLEN(DocNo) - STRLEN(Prefix) - STRLEN(FORMAT(Number));
EXIT(Prefix + PADSTR('',PadLength,'0') + FORMAT(Number));
END;
ERROR('Resulting number would be negative.');
---------------------------------
Results in: ABC00009
the resulting number has the same length.