Jump to content

please help, i am to dumb for simple array or eval


Go to solution Solved by Nine,

Recommended Posts

Posted

okay, i try to rewrite old autoit project from another guy. he saves things in ini file like this

$profilename1input = GUICtrlRead($profilename1)
IniWrite($IniFile, "profilename", "profilename1", $profilename1input)
$profilename2input = GUICtrlRead($profilename2)
IniWrite($IniFile, "profilename", "profilename2", $profilename2input)
$profilename3input = GUICtrlRead($profilename3)
IniWrite($IniFile, "profilename", "profilename3", $profilename3input)
$profilename4input = GUICtrlRead($profilename4)
IniWrite($IniFile, "profilename", "profilename4", $profilename4input)
$profilename5input = GUICtrlRead($profilename5)
IniWrite($IniFile, "profilename", "profilename5", $profilename5input)

so i thought, no problem, easy just do bash like eval or array .... something like this. tried it now 30 mins and soon i will damage something. please help

Local $profilename[5]
$counter = 1
While $counter <= 5
    $profilenameinput = GUICtrlRead($profilename[$counter])
    IniWrite($IniFile, "profilename", "profilename" & $counter, $profilenameinput)
    $counter += 1
WEnd

 

Posted (edited)

thank you for your fast answer. i like to count the variable too. i dont know how to do that maybe array is wrong and i need evil eval.maybe does something like this work?

Local $profilename[5]
For $i = 0 To UBound($profilename) - 1
    $profilename[$i] += ["profilename & $i"]
    ConsoleWrite($profilename[$i] & @CRLF)
    IniWrite($IniFile, "profilename", "profilename" & $i, $profilename[$i])
    
Next

im very sorry, the syntax is weird for me

Edited by meme18
Posted
2 minutes ago, Nine said:

I would strongly suggest that you create your controls into an array instead of separate variables.  But to answer your issue with a quick and dirty solution :

Local $sProfile
For $i = 1 To 5
  $sProfile = GUICtrlRead(Eval("profilename" & $i))
  IniWrite($IniFile, "profilename", "profilename" & $i, $sProfile)
Next

 

i swear i tried that 🤪okay, lets check again, but the array above? how can i do it with array?

  • Solution
Posted (edited)

@Nine@Subz many thx. got both working. i go with arrays. when i try this backwards with defining variables that should be reachable globally. how can i solve this?

$program1 = Null
$program2 = Null
$program3 = Null
$program4 = Null
$program5 = Null

 

i tried to use Assign but maybe im wrong again...

For $i = 1 To 5
    Assign ( "program" & $i ), "Null" )
Next

 

Edited by meme18

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...