Validar Cnpj
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
Curtidas 0
Respostas
Host
01/10/2003
Me envia teu email, que te envio o codigo!!
GOSTEI 0
Turbo Drive
01/10/2003
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´);
GOSTEI 0