Clube da Programação e Hardware
Gostaria de reagir a esta mensagem? Crie uma conta em poucos cliques ou inicie sessão para continuar.
Clube da Programação e Hardware

Tutorial, dicas, Programação, Hardware entre outros assuntos.
 
InícioInício  Últimas imagensÚltimas imagens  ProcurarProcurar  RegistarRegistar  Entrar  

 

 Validar CGC/CNPJ (Delphi, Forms)

Ir para baixo 
AutorMensagem
vanix




Mensagens : 26
Data de inscrição : 20/01/2011

Validar CGC/CNPJ (Delphi, Forms) Empty
MensagemAssunto: Validar CGC/CNPJ (Delphi, Forms)   Validar CGC/CNPJ (Delphi, Forms) EmptyQui Jan 20, 2011 8:18 am

unit Uvalida_cnpj;

Código:


interface
uses
    SysUtils;

implementation

function TestaCgc(xCGC: String):Boolean;
{Testa se o CGC é válido ou não}
Var
d1,d4,xx,nCount,fator,resto,digito1,digito2 : Integer;
Check : String;
begin
d1 := 0;
d4 := 0;
xx := 1;
for nCount := 1 to Length( xCGC )-2 do
    begin
    if Pos( Copy( xCGC, nCount, 1 ), '/-.' ) = 0 then
      begin
      if xx < 5 then
          begin
          fator := 6 - xx;
          end
      else
          begin
          fator := 14 - xx;
          end;
      d1 := d1 + StrToInt( Copy( xCGC, nCount, 1 ) ) * fator;
      if xx < 6 then
          begin
          fator := 7 - xx;
          end
      else
          begin
          fator := 15 - xx;
          end;
      d4 := d4 + StrToInt( Copy( xCGC, nCount, 1 ) ) * fator;
      xx := xx+1;
      end;
    end;
    resto := (d1 mod 11);
    if resto < 2 then
      begin
      digito1 := 0;
      end
  else
      begin
      digito1 := 11 - resto;
      end;
  d4 := d4 + 2 * digito1;
  resto := (d4 mod 11);
  if resto < 2 then
      begin
      digito2 := 0;
      end
  else
      begin
      digito2 := 11 - resto;
      end;
  Check := IntToStr(Digito1) + IntToStr(Digito2);
  if Check <> copy(xCGC,succ(length(xCGC)-2),2) then
      begin
      Result := False;
      end
  else
      begin
      Result := True;
      end;
end;

end.
Ir para o topo Ir para baixo
 
Validar CGC/CNPJ (Delphi, Forms)
Ir para o topo 
Página 1 de 1
 Tópicos semelhantes
-
» Criar um Alias através do seu programa - Delphi
» Controle de Estoque e vendas com Fontes em Delphi
» Controle de Estoque e vendas em Delphi Prontinho
» Como deixar as 1º letras maiusculas de um componente edit. (Delphi)
» Alterar cores do PageControl (Delphi) (Resolvido )

Permissões neste sub-fórumNão podes responder a tópicos
Clube da Programação e Hardware :: Programação-
Ir para: