30 Kasım 2011 Çarşamba

AXAPTA create sequential number

There is "Number Sequence class" for creating numbers for Axapta tables. But if you just want to create a "next number" function for just a string? Like "AB0001"->"AB0002". There isn't any built-in function in Axapta for that or I couldn't find. This is my number generator function:

Static str AutoNum(str Num)
{
    int i;
    int bas;
    str b;
    ;
    for (i=StrLen(num);i>=1;i--)
    {
        b=SubStr(num,i,1);
        if (b<"0" || b>"9")
        {
            bas=i+1;
            Break;
        }
        if (i==1)
            bas=1;
    }
    num=StrReplace(SubStr(num,1,bas-1)+
    Num2Str(Str2Num( SubStr(num,bas,StrLen(num) - bas + 1) )+1,
        StrLen(num) - bas + 1,0,1,0)," ","0");
    Return num;
}

Hiç yorum yok:

Yorum Gönder