Sign in to follow this  
Followers 0
Kmeersch

assign value to function

14 posts in this topic

Code is VBscript - how can I convert the bold line into AutoIt syntax?

Function getUpcGeneralCheck(digits)

Dim i, checkSum, strLen

strLen = Len(digits)

For i = 1 To strLen

If i Mod 2 = 1 Then

checkSum = checkSum + CInt(Mid(digits, strLen - i + 1, 1)) * 3

Else

checkSum = checkSum + CInt(Mid(digits, strLen - i + 1, 1))

End If

Next

getUpcGeneralCheck = checkSum Mod 10

If getUpcGeneralCheck <> 0 Then getUpcGeneralCheck = 10 - getUpcGeneralCheck

End Function

Share this post


Link to post
Share on other sites



$getUpcGeneralCheck = Mod($checkSum, 10)


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

:mellow:

getUpcGeneralCheck is the function not a variable...

??

Function getUpcGeneralCheck(digits)

Dim i, checkSum, strLen

strLen = Len(digits)

For i = 1 To strLen

If i Mod 2 = 1 Then

checkSum = checkSum + CInt(Mid(digits, strLen - i + 1, 1)) * 3

Else

checkSum = checkSum + CInt(Mid(digits, strLen - i + 1, 1))

End If

Next

getUpcGeneralCheck = checkSum Mod 10

If getUpcGeneralCheck <> 0 Then getUpcGeneralCheck = 10 - getUpcGeneralCheck

End Function

Share this post


Link to post
Share on other sites

:mellow:

getUpcGeneralCheck is the function not a variable...

??

Function getUpcGeneralCheck(digits)

Dim i, checkSum, strLen

strLen = Len(digits)

For i = 1 To strLen

If i Mod 2 = 1 Then

checkSum = checkSum + CInt(Mid(digits, strLen - i + 1, 1)) * 3

Else

checkSum = checkSum + CInt(Mid(digits, strLen - i + 1, 1))

End If

Next

getUpcGeneralCheck = checkSum Mod 10

If getUpcGeneralCheck <> 0 Then getUpcGeneralCheck = 10 - getUpcGeneralCheck

End Function

Sorry about that

Actually the last 2 lines of the VBS function don't look right at all. Where did you find that code?


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Code is VBscript - how can I convert the bold line into AutoIt syntax?

Function getUpcGeneralCheck(digits)

Dim i, checkSum, strLen

strLen = Len(digits)

For i = 1 To strLen

If i Mod 2 = 1 Then

checkSum = checkSum + CInt(Mid(digits, strLen - i + 1, 1)) * 3

Else

checkSum = checkSum + CInt(Mid(digits, strLen - i + 1, 1))

End If

Next

getUpcGeneralCheck = checkSum Mod 10

If getUpcGeneralCheck <> 0 Then getUpcGeneralCheck = 10 - getUpcGeneralCheck

End Function

You can't assign a value to a function... This wouldn't work in VBS either.


Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt

Share this post


Link to post
Share on other sites

Its hard to tell without the rest of the script. Its possible that it was intended to be recursive, but more likely that getUpcGeneralCheck is a global variable.

Share this post


Link to post
Share on other sites

full code listing

msgbox(1,"","",EAN13(123456789123))


;-------------------------------------------------------------------------------------------
;ut$il$ity Funcs - EAN/UPC ser$ies 
Func FirstFlagText($onedigit) 
    $onedigit = int($onedigit) 
   ;$if $onedigit = 0 Then $onedigit = 10 
    return Chr(33 + $onedigit) 
EndFunc 

Func SecondFlagText($onedigit) 
    $onedigit = int($onedigit) 
   ;$if $onedigit = 0 Then $onedigit = 10 
    return Chr(96 + $onedigit) 
EndFunc 

Func maskfilter($inpara, $coderange) 
    Dim $i, $charPos 
    maskfilter = "" 
    For $i = 1 To Len($inpara) 
        $charPos = stringinstr(1, $coderange, stringMid($inpara, $i, 1), 0) 
        if $charPos > 0 Then 
            return maskfilter + stringMid($inpara, $i, 1) 
        Endif 
    Next 
EndFunc 

Func convertSetAText($onedigit) 
    $onedigit = int($onedigit) 
   ;$if $onedigit = 0 Then $onedigit = 10 
    return Chr(48 + $onedigit) 
EndFunc 

Func convertSetCText($onedigit) 
    $onedigit = int($onedigit) 
   ;$if $onedigit = 0 Then $onedigit = 10 
    return Chr(80 + $onedigit) 
EndFunc 

Func convertSetBText($onedigit) 
    $onedigit = int($onedigit) 
   ;$if $onedigit = 0 Then $onedigit = 10 
    return Chr(64 + $onedigit) 
EndFunc 

Func convertCheckDigitText($onedigit) 
    $onedigit = int($onedigit) 
   ;$if $onedigit = 0 Then $onedigit = 10 
    return Chr(112 + $onedigit) 
EndFunc 

Func getUpcGeneralCheck($digits) 
    Dim $i, $checkSum, $strLen 
    $strLen = stringLen($digits) 
    For $i = 1 To $strLen 
        $resmod= Mod($i,2) 
        if $resmod = 1 Then 
            $checkSum = $checkSum + int(stringMid($digits, $strLen - $i + 1, 1)) * 3 
        Else 
            $checkSum = $checkSum + int(stringMid($digits, $strLen - $i + 1, 1)) 
        Endif 
    Next 
    getUpcGeneralCheck = Mod($checkSum,10)
            
    if getUpcGeneralCheck <> 0 Then 
        return 10 - getUpcGeneralCheck
    endif
    
EndFunc 


;EAN13 
;/*----------------------------------------------------------------------------------------*/ 
;/*Converts the $input text 
;o an EAN barcode. Accepts $input of 12 d$ig$its of numer$ic data.*/ 
;/*----------------------------------------------------------------------------------------*/ 
Func EAN13($inpara) 
    Dim $i, $checkDigit, $charToEncode, $res
    Dim $symbmod, $symset, $symPattern 
    Dim $charSet, $strSupplement, $charPos 
    
   ;charSet = "0123456789|" 
   ;$inpara = maskf$ilter($inpara, charSet) 
   ;$charPos = $inStr(1, $inpara, "|", 0) 
    $res=stringMid($inpara, 1, 1) 
    
    
    
    Select  
        Case $res=0
            $symbmod = "AAAAAA" 
        Case $res=1
            $symbmod = "AABABB" 
        Case $res=2
            $symbmod = "AABBAB" 
        Case $res=3 
            $symbmod = "AABBBA" 
        Case $res=4
            $symbmod = "ABAABB" 
        Case $res=5
            $symbmod = "ABBAAB" 
        Case $res=6
            $symbmod = "ABBBAA" 
        Case $res=7
            $symbmod = "ABABAB" 
        Case $res=8
            $symbmod = "ABABBA" 
        Case $res=9
            $symbmod = "ABBABA" 
    EndSelect 



    EAN13 = FirstFlagText(stringMid($inpara, 1, 1)) + SecondFlagText(stringMid($inpara, 2, 1)) 

    For $i = 3 To 7 
        $symPattern = stringmid($symbmod, $i - 1, 1) 
        if $symPattern = "A" Then 
            EAN13 = EAN13+ convertSetAText(stringmid($inpara, $i, 1)) 
        Else 
            if $symPattern = "B" Then 
                EAN13 = EAN13 + convertSetBText(stringmid($inpara, $i, 1)) 
            endif
        Endif 
    Next 
    
    EAN13 = EAN13 + "|" 
    
    For $i = 8 To 12 
        EAN13 = EAN13 + convertSetCText(stringmid($inpara, $i, 1)) 
    Next 
        
    $checkDigit = getUpcGeneralCheck($inpara) 
        
    return EAN13 + convertcheckDigitText($checkDigit) 
EndFunc

Share this post


Link to post
Share on other sites

... more likely that getUpcGeneralCheck is a global variable.

That's what I was thinking.


Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt

Share this post


Link to post
Share on other sites

vbscript that works fine!!

main

Sub main
    d = EAN13(WScript.Arguments(0))
    
End sub

'-------------------------------------------------------------------------------------------
'utility functions - EAN/UPC series 
Function FirstFlagText(onedigit) 
    onedigit = Int(onedigit) 
    'If onedigit = 0 Then onedigit = 10 
    FirstFlagText = Chr(33 + onedigit) 
End Function 
Function SecondFlagText(onedigit) 
    onedigit = Int(onedigit) 
    'If onedigit = 0 Then onedigit = 10 
    SecondFlagText = Chr(96 + onedigit) 
End Function 

Function maskfilter(inpara, coderange) 
    Dim i, charPos 
    maskfilter = "" 
    For i = 1 To Len(inpara) 
        charPos = InStr(1, coderange, Mid(inpara, i, 1), 0) 
        If charPos > 0 Then 
            maskfilter = maskfilter + Mid(inpara, i, 1) 
        End If 
    Next 
End Function 

Function convertSetAText(onedigit) 
    onedigit = Int(onedigit) 
    'If onedigit = 0 Then onedigit = 10 
    convertSetAText = Chr(48 + onedigit) 
End Function 

Function convertSetCText(onedigit) 
    onedigit = Int(onedigit) 
    'If onedigit = 0 Then onedigit = 10 
    convertSetCText = Chr(80 + onedigit) 
End Function 

Function convertSetBText(onedigit) 
    onedigit = Int(onedigit) 
    'If onedigit = 0 Then onedigit = 10 
    convertSetBText = Chr(64 + onedigit) 
End Function 

Function convertCheckDigitText(onedigit) 
    onedigit = Int(onedigit) 
    'If onedigit = 0 Then onedigit = 10 
    convertCheckDigitText = Chr(112 + onedigit) 
End Function 

Function getUpcGeneralCheck(digits) 
    Dim i, checkSum, strLen 
    strLen = Len(digits) 
    For i = 1 To strLen 
        If i Mod 2 = 1 Then 
            checkSum = checkSum + CInt(Mid(digits, strLen - i + 1, 1)) * 3 
        Else 
            checkSum = checkSum + CInt(Mid(digits, strLen - i + 1, 1)) 
        End If 
    Next 
    getUpcGeneralCheck = checkSum Mod 10 
    If getUpcGeneralCheck <> 0 Then getUpcGeneralCheck = 10 - getUpcGeneralCheck 
End Function 


'EAN13 
'/*----------------------------------------------------------------------------------------*/ 
'/*Converts the input text into an EAN barcode. Accepts input of 12 digits of numeric data.*/ 
'/*----------------------------------------------------------------------------------------*/ 
Function EAN13(inpara) 
    Dim i, checkDigit, charToEncode 
    Dim symbmod, symset, symPattern 
    Dim charSet, strSupplement, charPos 

    'charSet = "0123456789|" 
    'inpara = maskfilter(inpara, charSet) 
    'charPos = InStr(1, inpara, "|", 0) 

    Select Case Mid(inpara, 1, 1) 
        Case 0: symbmod = "AAAAAA" 
        Case 1: symbmod = "AABABB" 
        Case 2: symbmod = "AABBAB" 
        Case 3: symbmod = "AABBBA" 
        Case 4: symbmod = "ABAABB" 
        Case 5: symbmod = "ABBAAB" 
        Case 6: symbmod = "ABBBAA" 
        Case 7: symbmod = "ABABAB" 
        Case 8: symbmod = "ABABBA" 
        Case 9: symbmod = "ABBABA" 
    End Select 

    EAN13 = FirstFlagText(Mid(inpara, 1, 1)) + SecondFlagText(Mid(inpara, 2, 1)) 

    For i = 3 To 7 
        symPattern = Mid(symbmod, i - 1, 1) 
        If symPattern = "A" Then 
            EAN13 = EAN13 + convertSetAText(Mid(inpara, i, 1)) 
        ElseIf symPattern = "B" Then 
            EAN13 = EAN13 + convertSetBText(Mid(inpara, i, 1)) 
        End If 
    Next 
    EAN13 = EAN13 + "|" 
    For i = 8 To 12 
        EAN13 = EAN13 + convertSetCText(Mid(inpara, i, 1)) 
    Next 
    checkDigit = getUpcGeneralCheck(inpara) 
    EAN13 = EAN13 + convertCheckDigitText(checkDigit) 
End Function

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Its just an alternate way to return values for vbs. Instead of writing Return myValue, you just set the function name to a value.

My quick vbs test:

Dim myTest
myTest = tester1(3)
WScript.echo myTest

Function tester1 (digit)
    tester1 = digit * 4
End Function
Edited by zorphnog

Share this post


Link to post
Share on other sites

Here's my AutoIt-ified version of what I believe this function is doing:

Func getUpcGeneralCheck($digits) 
    Dim $i, $checkSum, $strLen, $getUpcGeneralCheck
    $strLen = StringLen($digits) 
    For $i = 1 To $strLen 
        If Mod($i, 2) = 1 Then 
            $checkSum = $checkSum + Int(StringMid($digits, ($strLen - $i + 1), 1)) * 3 
        Else 
            $checkSum = $checkSum + Int(StringMid($digits, ($strLen - $i + 1), 1)) 
        EndIf 
    Next 
    $getUpcGeneralCheck = Mod($checkSum, 10)
    If $getUpcGeneralCheck <> 0 Then $getUpcGeneralCheck = 10 - $getUpcGeneralCheck 
 Return $getUpcGeneralCheck
EndFunc

Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt

Share this post


Link to post
Share on other sites

nope = gives an empty value. :mellow:

Share this post


Link to post
Share on other sites

nope = gives an empty value. :mellow:

Then the rest of your code isn't calling the function properly. Try this - you will see a message box stating "5":

MsgBox(0,"",getUpcGeneralCheck(5))

Func getUpcGeneralCheck($digits) 
    Dim $i, $checkSum, $strLen, $getUpcGeneralCheck
    $strLen = StringLen($digits) 
    For $i = 1 To $strLen 
        If Mod($i, 2) = 1 Then 
            $checkSum = $checkSum + Int(StringMid($digits, ($strLen - $i + 1), 1)) * 3 
        Else 
            $checkSum = $checkSum + Int(StringMid($digits, ($strLen - $i + 1), 1)) 
        EndIf 
    Next 
    $getUpcGeneralCheck = Mod($checkSum, 10)
    If $getUpcGeneralCheck <> 0 Then $getUpcGeneralCheck = 10 - $getUpcGeneralCheck 
 Return $getUpcGeneralCheck
EndFunc

Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt

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  
Followers 0