Jump to content
Sign in to follow this  
ter-pierre

Traslate to AutoIT

Recommended Posts

ter-pierre

I have the vaconvert.au3 and is very good.

Any one knows about some thing like this that do the same with .js scripts?

Pierre

Share this post


Link to post
Share on other sites
seandisanti

I have the vaconvert.au3 and is very good.

Any one knows about some thing like this that do the same with .js scripts?

Pierre

don't know if there's a UDF but if you post your .js code someone can probably translate it for you.

Share this post


Link to post
Share on other sites
ter-pierre

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;
 }

Share this post


Link to post
Share on other sites
seandisanti

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

Share this post


Link to post
Share on other sites
LxP

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

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.