Jump to content

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


meme18
 Share

Go to solution Solved by Nine,

Recommended Posts

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

 

Link to comment
Share on other sites

Not sure what you mean since $profileName[x] isn't associated with a control, so nothing for GuiCtrlRead to read, or do you mean something like:

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

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

  • Solution

Sorry I deleted my post instead of editing it. :ermm:

Anyway, to create an array of controls, you would do something like this :

GUICreate("")
Local $aIDtest[5]
For $i = 0 To UBound($aIDtest) - 1
  $aIDtest[$i]  = GUICtrlCreateInput("test " & $i, 10, 10 + $i * 30)
Next
GUISetState()

Sleep(5000)

 

Link to comment
Share on other sites

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...