Search code examples
arraysfunctionloopsautoit

Functions and loops


I am trying to make the function _EncryptionProcess() take arrays 1 by 1 and process them. I realized you can't have functions inside For loops.

The location in which the arrays need to be taken is where $aArray is typed, the arrays are stored in this value. The other variable defines the key size and value.

;Cuts the input up into piece; 
$VariableToBeCut = "12345678"
$aArray = StringRegExp($VariableToBeCut, ".{2}", 3)
MsgBox(0, "die", $aArray[0]) ; personal check to make sure array works

$DataToBeEncrypted=_EncryptionProcess($aArray, $keyvalue, $keysize, 1) ;$aArray needs to be where the different arrays are processed
MsgBox(0, "Encrypted data", $DataToBeEncrypted)

Solution

  • This is how you should process array elements.

    ;Cuts the input up into piece;
    $VariableToBeCut = "12345678"
    $aArray = StringRegExp($VariableToBeCut, ".{2}", 3)
    
    ConsoleWrite("Array element 0: " & $aArray[0] & @LF) ; personal check to make sure array works
    
    For $i = 0 To UBound($aArray)-1
    
        $DataToBeEncrypted = _EncryptionProcess($aArray[$i], $keyvalue, $keysize, 1)
    
        ConsoleWrite("Element " & $i & " : " & $aArray[$i] & " DataToBeEncrypted: " & $DataToBeEncrypted & @LF)
    
    Next