Fórum Validar Cnpj #185525
01/10/2003
0
Olá, eu sou novo aqui e queria saber como que eu uso a função pra validadar o cgc, eu tenho a função que eu baxei aqui mesmo nas dicas, so naum sei usa-la, como eu faço por favor!!!!
Derodrigo
Curtir tópico
+ 0
Responder
Posts
01/10/2003
Host
Me envia teu email, que te envio o codigo!!
Responder
Gostei + 0
02/10/2003
Turbo Drive
Função para verificar o CNPJ:
function TFPrincipal.VerificaCNPJ(CNPJ: string): Boolean;
var
CNPJCalc: string;
SomaCNPJ, CNPJDigit: Integer;
I: Byte;
begin
try
CNPJCalc:= Copy(CNPJ, 1, 12);
SomaCNPJ:= 0;
for I:= 1 to 4 do
SomaCNPJ:= SomaCNPJ + StrToInt(Copy(CNPJCalc, I, 1)) * (6 - I);
for I:= 1 to 8 do
SomaCNPJ:= SomaCNPJ + StrToInt(Copy(CNPJCalc, I + 4, 1)) * (10 - I);
CNPJDigit:= 11 - SomaCNPJ mod 11;
if CNPJDigit in [10, 11] then
CNPJCalc:= CNPJCalc + ´0´
else
CNPJCalc:= CNPJCalc + IntToStr(CNPJDigit);
SomaCNPJ:= 0;
for I:= 1 to 5 do
SomaCNPJ:= SomaCNPJ + StrToInt(Copy(CNPJCalc, I, 1)) * (7 - I);
for I:= 1 to 8 do
SomaCNPJ:= SomaCNPJ + StrToInt(Copy(CNPJCalc, I + 5, 1)) * (10 - I);
CNPJDigit:= 11 - SomaCNPJ mod 11;
if CNPJDigit in [10, 11] then
CNPJCalc:= CNPJCalc + ´0´
else
CNPJCalc:= CNPJCalc + IntToStr(CNPJDigit);
Result:= (CNPJ = CNPJCalc);
except
Result:= False;
end;
end;
Vc usa assim:
if FPrincipal.VerificaCNPJ(edit1.Text) then
showmessage(´deu certo´)
else
showmessage(´não deu certo´);
function TFPrincipal.VerificaCNPJ(CNPJ: string): Boolean;
var
CNPJCalc: string;
SomaCNPJ, CNPJDigit: Integer;
I: Byte;
begin
try
CNPJCalc:= Copy(CNPJ, 1, 12);
SomaCNPJ:= 0;
for I:= 1 to 4 do
SomaCNPJ:= SomaCNPJ + StrToInt(Copy(CNPJCalc, I, 1)) * (6 - I);
for I:= 1 to 8 do
SomaCNPJ:= SomaCNPJ + StrToInt(Copy(CNPJCalc, I + 4, 1)) * (10 - I);
CNPJDigit:= 11 - SomaCNPJ mod 11;
if CNPJDigit in [10, 11] then
CNPJCalc:= CNPJCalc + ´0´
else
CNPJCalc:= CNPJCalc + IntToStr(CNPJDigit);
SomaCNPJ:= 0;
for I:= 1 to 5 do
SomaCNPJ:= SomaCNPJ + StrToInt(Copy(CNPJCalc, I, 1)) * (7 - I);
for I:= 1 to 8 do
SomaCNPJ:= SomaCNPJ + StrToInt(Copy(CNPJCalc, I + 5, 1)) * (10 - I);
CNPJDigit:= 11 - SomaCNPJ mod 11;
if CNPJDigit in [10, 11] then
CNPJCalc:= CNPJCalc + ´0´
else
CNPJCalc:= CNPJCalc + IntToStr(CNPJDigit);
Result:= (CNPJ = CNPJCalc);
except
Result:= False;
end;
end;
Vc usa assim:
if FPrincipal.VerificaCNPJ(edit1.Text) then
showmessage(´deu certo´)
else
showmessage(´não deu certo´);
Responder
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)