Jump to content

Func with parameters with saving results


Go to solution Solved by Subz,

Recommended Posts

Hello,

maybe this topic exist in forum, I just don't know how should I search it.

The idea of my function is go get 2 inputs from GUI and run on same function.

 

It's looks like this 

 

; GUI has these created inputs
$firstInput = GUICtrlCreateInput("", x, x, x, x)
$secondInput = GUICtrlCreateInput("", x, x, x, x)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $buttonToExecute
            $firstValue = GUICtrlRead($firstInput)
            $secondValue = GUICtrlRead($secondInput)
            _executionFunc($firstValue)
            _executionFunc($secondValue)
    EndSwitch
WEnd

So the function collect data to Array for $firstValue and then converts _ArrayToString to another variable $collectedDataFromFirstValue = "here is all collected data from array" with all data in one variable (which is good for me),

then next step is run function again with $secondValue and here is my issue, how I can save all my collected values in $collectedDataFromFirstValue without overwrite? Because If the function runs again with all $firstValue data saved before in array then it gets overwritten by $secondValue and moved again to $collectedDataFromFirstValue.

 

Hope I explained well to understand what I meant. 

 

Edited by diff
Link to post
Share on other sites
  • Solution

Use two parameters for example: _executionFunc($firstValue, $secondValue) and then process both values at the same time within the function.  You could also use a flag

Basic example (note, don't really understand the need for _ArrayToString, or if you're adding, concatenating data to $collectedDataFromFirstValue)

Global $collectedDataFromFirstValue = ""
_excutionFunc($firstValue, 1)
_excutionFunc($secondValue)
Func _excutionFunc($_Value, $_iFlag = 0)
    Switch $_iFlag
        Case 1
            $collectedDataFromFirstValue &= $_Value
        Case Else
            ;~ Do something for other values
    EndSwitch
EndFunc

 

Link to post
Share on other sites
47 minutes ago, Subz said:

Use two parameters for example: _executionFunc($firstValue, $secondValue) and then process both values at the same time within the function.  You could also use a flag

Basic example (note, don't really understand the need for _ArrayToString, or if you're adding, concatenating data to $collectedDataFromFirstValue)

Global $collectedDataFromFirstValue = ""
_excutionFunc($firstValue, 1)
_excutionFunc($secondValue)
Func _excutionFunc($_Value, $_iFlag = 0)
    Switch $_iFlag
        Case 1
            $collectedDataFromFirstValue &= $_Value
        Case Else
            ;~ Do something for other values
    EndSwitch
EndFunc

 

 

In my case I cannot process both values at the same time within function, so the $_iFlag option works perfectly for me and separates values data with two different variables.

 

Amazing, totally forgot about flags with Switch, thank you :)

 

_ArrayToString I use because the collected words from $firstValue and $secondValue I need only in one line delimited by comma, so I thought that this could be the best solution for me

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...