aquinco
aquinco

Reputation: 3

Create a function that checks if ID number satisfies criteria

I'm new into NAV so maybe my question will seem a bit noob but here it goes. I created a table which has a field called ID number where user needs to enter a 10-digit Biginteger (or Code, IDK what is better) which represents his/her's ID. I must create a function that will check if this number is correct by checking if it satisfies following criteria:

If number is ABCDEFGHIJ, then digit J (which is called control digit) must be equal to: J=13-( 7*(A+G) + 6*(B+H) + 5*(C+I) + 4*(D+J)) MOD 13

and also, needs to satisfy criteria below:

J <= 9 -> X = J
J > 9 -> X = 0

I thought using function FORMAT first to convert integer to string and then COPYSTR for each of local variables A,B,C,D... but it doesn't work :( Can anyone please help me out with correct code?

Upvotes: 0

Views: 100

Answers (2)

Alexander Drogin
Alexander Drogin

Reputation: 671

You can try this code as it worked for me:

Num : BigInteger;
Digits : Array of Byte;
I : Integer;

FOR i := 10 DOWNTO 1 DO BEGIN
  Digits[i] := Num MOD 10;
  Num := Num DIV 10;
END;

Let me know if it doesn't work for you.

Upvotes: 0

Mak Sim
Mak Sim

Reputation: 2334

Str := format("Id"); A:=Str[1]; B:=Str[2];

Etc...

Or if you want A,B,C as integers then.

Str := format("Id"); Evaluate(A, Str[1]); Evaluate(B, Str[2]);

Upvotes: 1

Related Questions