Jump to content

Traslate to AutoIT


Recommended Posts

well... here is it

// the function receives as a parameter an string
 function checaCPF (CPF) {
    if (CPF.length != 11 || CPF == "00000000000" || CPF == "11111111111" ||
        CPF == "22222222222" || CPF == "33333333333" || CPF == "44444444444" ||
        CPF == "55555555555" || CPF == "66666666666" || CPF == "77777777777" ||
        CPF == "88888888888" || CPF == "99999999999")
        return false;
    soma = 0;
    for (i=0; i < 9; i ++)
        soma += parseInt(CPF.charAt(i)) * (10 - i);
    resto = 11 - (soma % 11);
    if (resto == 10 || resto == 11)
        resto = 0;
    if (resto != parseInt(CPF.charAt(9)))
        return false;
    soma = 0;
    for (i = 0; i < 10; i ++)
        soma += parseInt(CPF.charAt(i)) * (11 - i);
    resto = 11 - (soma % 11);
    if (resto == 10 || resto == 11)
        resto = 0;
    if (resto != parseInt(CPF.charAt(10)))
        return false;
    return true;
 }
Link to comment
Share on other sites

well... here is it

// the function receives as a parameter an string
 function checaCPF (CPF) {
    if (CPF.length != 11 || CPF == "00000000000" || CPF == "11111111111" ||
        CPF == "22222222222" || CPF == "33333333333" || CPF == "44444444444" ||
        CPF == "55555555555" || CPF == "66666666666" || CPF == "77777777777" ||
        CPF == "88888888888" || CPF == "99999999999")
        return false;
    soma = 0;
    for (i=0; i < 9; i ++)
        soma += parseInt(CPF.charAt(i)) * (10 - i);
    resto = 11 - (soma % 11);
    if (resto == 10 || resto == 11)
        resto = 0;
    if (resto != parseInt(CPF.charAt(9)))
        return false;
    soma = 0;
    for (i = 0; i < 10; i ++)
        soma += parseInt(CPF.charAt(i)) * (11 - i);
    resto = 11 - (soma % 11);
    if (resto == 10 || resto == 11)
        resto = 0;
    if (resto != parseInt(CPF.charAt(10)))
        return false;
    return true;
 }
here ya go...

// the function receives as a parameter an string
Func checaCPF ($CPF) {
    if Not StringLen($CPF) = 11 Or $CPF = "00000000000" Or $CPF = "11111111111" Or $CPF = "22222222222" Or  $CPF = "33333333333" Or $CPF = "44444444444" Or $CPF = "55555555555" Or $CPF = "66666666666" Or $CPF = "77777777777" Or $CPF = "88888888888" Or $CPF = "99999999999") Then Return (0)
    $soma = 0;
    for $i=0 to 8
        $soma += Int(StringMid($CPF,$i,1) * (10 - i)
    $resto = 11 - Mod($soma,11)
    if $resto = 10 Or $resto = 11 Then $resto = 0
    if Not $resto = Int(StringMid($CPF,9,1)) Then Return(0)
    $soma = 0;
    for $j = 0 to 9
        $soma += Int(StringMid($CPF,$j,1)) * (11 - $j)
    $resto = 11 - Mod($soma,11)
    if $resto = 10 Or $resto = 11 Then $resto = 0
    if Not $resto = Int(StringMid($CPF,10,1))Then return(0)
    Return(1)
EndFunc
Link to comment
Share on other sites

Small logic glitch:

if Not StringLen($CPF) = 11 Or ...

Equivalent to:

If (Not StringLen($CPF)) = 11 Or ...

Evaluates to:

; Either:
If 0 = 11 Or ...; for non-empty strings
; Or:
If 1 = 11 Or ...; for empty strings

Therefore needs brackets:

If Not (StringLen($CPF) = 11) Or ...

Better still:

If StringLen($CPF) <> 11 Or ...
Edited by LxP
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...