Below function was created to autoincrement aplhanumeric field,
3 parameters are needed for executing the function, Previous or max string value, numbers of characters in a field, number of integer values in a field.
Function auto_incr(&Var As string, &Nc As integer, &ni As integer) Returns string
Local integer &max_int, &i_str;
Local boolean &maxint;
Local boolean &max_str;
Local string &str_i, &str_e, &substr;
&str_i = "";
For &c = 1 To &ni
&str_i = &str_i | "9";
End-For;
&max_int = Value(&str_i);
&str_e = Substring(&Var, &Nc + 1, &ni);
&i_str = Value(&str_e);
If &i_str < &max_int Then
&i_str = &i_str + 1;
&var1 = Substring(&Var, 1, &Nc) | &i_str;
Else
&maxint = True;
&str_i = "";
For &c = 1 To &ni - 1
&str_i = &str_i | "0";
End-For;
&str_i = &str_i | "1";
End-If;
If &maxint = True Then
For &c = &Nc To 1 Step - 1
&substr = Substring(&Var, &c, 1);
rem check between 65 to 90;
If Code(&substr) >= 65 And
Code(&substr) < 90 Then
&substr = Char(Code(&substr) + 1);
&var1 = Replace(&Var, &c, 1, &substr);
&var1 = Replace(&var1, &Nc + 1, &ni, &str_i);
Break;
End-If;
End-For;
End-If;
Return &var1;
End-Function;
&str = "AZZ899";
&res = auto_incr(&str, 3, 3);
WinMessage(&res);
No comments:
Post a Comment