Código
const
String1 = '090807060504030201';
String2 = '100908070605040302';
var
i,j,Digito: byte;
Controle, DigitoInformado: string[2];
StringX: string;
Soma: smallint;
begin
sCNH := Copy('00000000000'+Trim(sCNH),(Length(Trim(sCNH))+11)-10,11 );
Controle := ' ';
DigitoInformado := Copy( sCNH,10,2 );
StringX := String1;
if sCNH <> '00000000000' then
for i := 1 to 2 do
begin
Soma := 0;
if i = 2 then StringX := String2;
for j := 1 to 9 do
Soma := Soma + ( StrToInt(sCNH[j]) * StrToIntDef( Copy( StringX,j+(j-1),2 ),0 ) );
Digito := Soma Mod 11;
if Digito >= 10 then
Digito := 0;
Controle[i] := IntToStr( Digito )[1];
end;
Result := Controle = DigitoInformado;
if not Result and lExibeMsg then
Application.MessageBox('Número de CNH inválido!','Atenção',mb_TaskModal + mb_IconWarning);
end;
Planeta Delphi - www.planetadelphi.com.br - Todos os direitos reservados | Copyright 2001-2009