Topic: script

Hello!
I am a beginner and need help with the following:

I have a TextEdit field in which a 9-digit number is entered.

During the introduction I want to check if it is valid.
The formula is as follows:
(1 * a1) + (2 * a2) + (3 * a3) + (4 * a4) + (5 * a5) + (6 * a6) + (7 * a7) + (8 * a8)
where a1 to a8 are the first 8 digits.
Add the result if it is two digits and compare it with the last digit.

2 (edited by CDB 2021-01-02 23:26:20)

Re: script

iwkom,

Add the result if it is two digits and compare it with the last digit.

If the result is two digits, do they get subtracted from the nearest multiple of 10 to produce the check digit?

Are the numbers added as single digits or as actual numbers?


Using your formula for example, the eight digit number 83102340 = 8 + 6 + 3 + 0 + 10 + 18 + 28 + 0 = 73, if adding as actual numbers. But if added as single digits the number will be  8 + 6 + 3 +  0 +1 + 0 + 1 + 8 + 2 + 8 + 0 = 38.


Does the resulting number get deducted from the nearest value of 10  which in the above examples would either result in a check digit of either 7  or 2?


If you could clarify the above, a function could be written for you.

On a clear disk you can seek forever

3 (edited by iwkom 2021-01-03 00:19:40)

Re: script

the sum is calculated:
1 * a1 + 2 * a2 + 3 * a3 + 4 * a4 + 5 * a5 + 6 * a6 + 7 * a7 + 8 * a8,
where a1 is the first digit, a2 is the second, and so on.
• the balance under module 11 of the amount is calculated
• if the remainder is other than 10, it is defined as the ninth digit
• if the remainder is 10, the amount is calculated
3 * a1 + 4 * a2 + 5 * a3 + 6 * a4 + 7 * a5 + 8 * a6 + 9 * a7 + 10 * a8,
where a1 is the first digit, a2 is the second, and so on
• the balance under module 11 of the new amount is calculated
• if the remainder is other than 10, it is defined as the ninth digit, and if it is ten - for
the ninth digit is set to "0"

According to your example, 83102340 = 8 + 6 + 3 + 0 + 10 + 18 + 28 + 0 = 73
if the last 9th digit is 0, it is considered valid.

It is a question of checking the validity of the UIC under the Bulgarian legislation.

I did it very easily with PHP, but I'm a beginner with DELPHI.

I found this, but I can't embed it in MVD

Function IsDN(dn:String;var code:integer):Boolean;
var
    L,i:integer;
    v,vs,vm:Longint;
begin
    Result:=False;
    dn:=TrimAll_t(dn);
    L:=Length(dn);
    if L<>10 then begin
        Result:=False;
        code:=1;
        Exit;
    end;
    if dn='9999999999' then begin
               Result:=True;
               Exit;
             end; 
    vs:=0;
    v:=0;
    For i:=1 to L do begin
        if not (dn[i] in ['0'..'9']) then begin
            {if there are # characters from a number}
            code:=2;
            Exit;
        end;
        v:=StrToIntDef(dn[i],0);
        case i of
            1:vs:=vs+v*4;
            2:vs:=vs+v*3;
            3:vs:=vs+v*2;
            4:vs:=vs+v*7;
            5:vs:=vs+v*6;
            6:vs:=vs+v*5;
            7:vs:=vs+v*4;
            8:vs:=vs+v*3;
            9:vs:=vs+v*2;
        end;{case i}
    end;{For i:=1 to L do begin}
    if vs=0 then begin
        code:=3;
        exit;
    end;
    vm:=vs mod 11;
    case vm of
        0:begin{the last number in the DN must be 0}
                if v<>0 then begin
                    code:=4;
                    exit;
                end;
            end;
        1:begin{wrong DN}
                code:=5;
                Exit;
            end;
        2..10:
            begin
                if v<>(11-vm) then begin
                    code:=6;
                    exit;
                end;          
            end;
    end;{case vm}
  Result:=True;
end;