Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Modulo11LinhaDigitavel(Valor: String; Base: Integer = 9; Resto : boolean = false) : string;
- var
- Soma : integer;
- Contador, Peso, Digito : integer;
- I: integer;
- begin
- for I := 1 to Length(Valor) do
- begin
- if Pos(Valor[I], '0123456789')=0 then
- begin
- Delete(Valor, I, 1);
- end;
- end;
- Valor := Copy(Valor, 1, 4) +
- Copy(Valor, 33,15) +
- Copy(Valor, 5,5) +
- Copy(Valor, 11,10) +
- Copy(Valor, 22,10);
- Valor := Copy(Valor, 1, 4) + Copy(Valor, 6, 39);
- Soma := 0;
- Peso := 2;
- for Contador := Length(Valor) downto 1 do
- begin
- Soma := Soma + (StrToInt(Valor[Contador]) * Peso);
- if Peso < Base then
- Peso := Peso + 1
- else
- Peso := 2;
- end;
- if Resto then
- Result := IntToStr(Soma mod 11)
- else
- begin
- Digito := 11 - (Soma mod 11);
- if (Digito > 9) then
- Digito := 0;
- Result := IntToStr(Digito);
- end;
- // correção
- if Result = '0' then Result := '1';
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement