Ver Mensaje Individual
  #2  
Antiguo 04-12-2008
Avatar de marcoszorrilla
marcoszorrilla marcoszorrilla is offline
Capo
 
Registrado: may 2003
Ubicación: Cantabria - España
Posts: 11.221
Reputación: 10
marcoszorrilla Va por buen camino
Mira esta función:

Código Delphi [-]

//****** COMPRUEBA LOS DIGITOS DE CONTROL DEL CCC ******************************
function ControlDigitosCCC(CCC:string):boolean;
const
 Pesos:array [0..9] of byte =(1,2,4,8,5,10,9,7,3,6);
 var
 DC1,DC2,c,Resto:integer;
 st1,st2:string;
begin
 Result:=False;
 st1:=Copy(CCC,1,8);
 st2:=Copy(CCC,11,10);
 DC1:=0;
 DC2:=0;

 for c:=0 to length(st1)-1 do
 begin
   try
   Dc1:=Dc1+strtoint(copy(st1,c+1,1))*Pesos[c+2];
   except
     exit;
   end;
 end;

 Resto:=DC1 mod 11;
 Dc1:=11-Resto;
 if DC1=10 then DC1:=1;
 if DC1=11 then DC1:=0;

 for c:=0 to length(st2)-1 do
 begin
   try
     Dc2:=Dc2+strtoint(copy(st2,c+1,1))*Pesos[c];
   except
     exit;
   end;
 end;

 Resto:=DC2 mod 11;
 Dc2:=11-Resto;
 if DC2=10 then DC2:=1;
 if DC2=11 then DC2:=0;

 try
   if (DC1=strtoint(Copy(CCC,9,1))) and (DC2=strtoint(Copy(CCC,10,1))) then Result:=True;
 except
 end;
end;

Comprobaciones en esta dirección:

Un Saludo.
__________________
Guía de Estilo de los Foros
Cita:
- Ça c'est la caisse. Le mouton que tu veux est dedans.
Responder Con Cita