Código
Segue um exemplo simples com cinco algarimos:
Matrícula: 00113-9
=> (0*5) + (0*6) + (1*7) + (1*8) + (3*9) = 0 + 0 + 7 + 8 + 27 = 42
=> 42 mod 11 => DV é 9}
//Calcula o digito verificador cpf
function DV11(Matr : string): string;
{Calculo pelo módulo 11 - tabela 2..9}
var
X, Cont, Soma, DV, NMatr : integer;
begin
Cont := 5; Soma := 0;
For X := 1 to 5 do
begin
NMatr := StrToInt(Copy(Matr,Cont-4,1));
Soma := Soma + (NMatr * Cont);
Inc(Cont);
end;
DV := Soma mod 11;
if DV > 9 then DV := 11 - DV;
Result := IntToStr(DV);
end;
Planeta Delphi - www.planetadelphi.com.br - Todos os direitos reservados | Copyright 2001-2009