Jump to content

Manipulating a function


Recommended Posts

the code that i have written is extremely long so i will post only the part i am having trouble with. I am trying to make the function "_EncryptionProcess" take the arrays 1 by 1 and then process them. Unfortunately after much reading on this forum i have realised that you cant have functions inside For loops. 
 The location in which the arrays need to be taken is where the "$aArray" is typed, the arrays are stored in this value. The other variable defines the key size being used and the key value being used. 

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

 

Link to comment
Share on other sites

  • Moderators

bahjat,

Unfortunately after much reading on this forum i have realised that you cant have functions inside For loops

Really? You cannot define functions inside loops, but there is nothing to prevent you from calling them. And the code you posted should run - although you will need to extract the elements from the array you pass as a parameter within the _EncryptionProcess function.  This shows the how you might do it:

#include <Array.au3>
#include <MsgBoxConstants.au3>

Global $keysize, $keyvalue = "-simulate-encrypted"

$VariableToBeCut = "12345678"
$DataToBeEncrypted = StringRegExp($VariableToBeCut, ".{2}", 3)

; Display original data
_ArrayDisplay($DataToBeEncrypted, "Before", Default, 8)

; Pass array to encryption process
$aDataAfterEncryption = _EncryptionProcess($DataToBeEncrypted, $keyvalue, $keysize, 1) ;$aArray needs to be where the different arrays are processed

; Display returned data
_ArrayDisplay($aDataAfterEncryption, "After", Default, 8)

Func _EncryptionProcess($aArray, $keyvalue, $keysize, $iVal)

    For $i = 0 To UBound($aArray) - 1
        ; Display each element
        MsgBox($MB_SYSTEMMODAL, "Unencrypted data", $aArray[$i])
        ; Call a function from inside the loop to encrypt the value
        $aArray[$i] = _Encrypt($aArray[$i])
    Next
    ; Return amended array
    Return $aArray

EndFunc

Func _Encrypt($sString)

    ; Simulate encryption
    $sString = $sString & $keyvalue
    ; Return encrupted value
    Return $sString

EndFunc

Does that help explain how to do what you require? 

M23 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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

×
×
  • Create New...