Hello,

We have a program at work wich runs on C# (I am new to this).

There is a function (seen in the code below) which numbers ID's.

When I choose 3 letters like 'AZM' the numbering works.

AZM001
AZM002
AZM003
etc...

But when I want to use numbers: 001001, 001002, 001003 it doesnt work.
I get:
001001 (this is good)
011002 (this should be 001002)
011003 (this should be 001003)

I hope that you guys can help.

Code:
function GetPaddedPatNo(LastID, padding)
{
  var snums = '0123456789';
  var sres = '';
  var i = 0;
   // remove all non-numerical characters
 
 for(i=0; i< LastID.length; i++)
  {
    if(snums.indexOf(LastID.substr(i,1)) >=  0)
      sres += LastID.substr(i,1);
  }

  var ires = new Number(sres);
  if((ires.NaN) || (ires == 0))
    ires = 0;

  if(ires > 9999)
    ires = ires % 10000;

 var nextPat = ires + 1;
  sres = nextPat + '';
  while(sres.length < padding)
    sres = '0' + sres;

  return(sres);
}
@INST_SHORTCODE + GetPaddedPatNo(LastPfxPatNo(@INST_SHORTCODE), 3);