USUÁRIO:      SENHA:        SALVAR LOGIN ?    Adicione o VBWEB na sua lista de favoritos   Fale conosco 

 

  Dicas

  ASP - Active Server Page    (Miscelâneas)

Título da Dica:  Calcular CPF
Postada em 26/9/2003 por Mago_Pc            
<%
if Request("chkCPF") = "on" then
CalculaCPF()
else
CalculaCNPJ()
end if

'| ************************************************ |
'|                           Funcao para calcular CPF                            |
'| ************************************************ |

function CalculaCPF()

Dim RecebeCPF, Numero(11), soma, resultado1, resultado2

RecebeCPF = Request("CampoNumero")

'Retirar todos os caracteres que nao sejam 0-9

s=""
for x=1 to len(RecebeCPF)
ch=mid(RecebeCPF,x,1)
if asc(ch)>=48 and asc(ch)<=57 then
s=s & ch
end if
next
RecebeCPF = s

if len(RecebeCPF) <> 11 then
response.write("<h1>&Eacute; obrigat&oacute;rio o CPF com 11 d&iacute;gitos</h1>")
elseif RecebeCPF = "00000000000" then
response.write("<h1>CPF Inválido</h1>")
else

Numero(1) = Cint(Mid(RecebeCPF,1,1))
Numero(2) = Cint(Mid(RecebeCPF,2,1))
Numero(3) = Cint(Mid(RecebeCPF,3,1))
Numero(4) = Cint(Mid(RecebeCPF,4,1))
Numero(5) = Cint(Mid(RecebeCPF,5,1))
Numero(6) = CInt(Mid(RecebeCPF,6,1))
Numero(7) = Cint(Mid(RecebeCPF,7,1))
Numero(8) = Cint(Mid(RecebeCPF,8,1))
Numero(9) = Cint(Mid(RecebeCPF,9,1))
Numero(10) = Cint(Mid(RecebeCPF,10,1))
Numero(11) = Cint(Mid(RecebeCPF,11,1))


soma = 10 * Numero(1) + 9 * Numero(2) + 8 * Numero(3) + 7 * Numero(4) + 6 * Numero(5) + 5 * Numero(6) + 4 * Numero(7) + 3 * Numero(8) + 2 * Numero(9)

soma = soma -(11 * (int(soma / 11)))

if soma = 0 or soma = 1 then
resultado1 = 0
else
resultado1 = 11 - soma
end if

if resultado1 = Numero(10) then

soma = Numero(1) * 11 + Numero(2) * 10 + Numero(3) * 9 + Numero(4) * 8 + Numero(5) * 7 + Numero(6) * 6 + Numero(7) * 5 + Numero(8) * 4 + Numero(9) * 3 + Numero(10) * 2

soma = soma -(11 * (int(soma / 11)))

if soma = 0 or soma = 1 then
resultado2 = 0
else
resultado2 = 11 - soma
end if

if resultado2 = Numero(11) then
response.write("<h1>CPF Válido</h1>")
else
response.write("<h1>CPF Inválido</h1>")
end if
else
response.write("<h1>CPF Inválido</h1>")
end if
end if

end function
%>
 


CyberWEB Network Ltda.    © Copyright 2000-2024   -   Todos os direitos reservados.
Powered by HostingZone - A melhor hospedagem para seu site
Topo da página