Jump to content

Append Variable With For Loop Variable


Go to solution Solved by Andreik,

Recommended Posts

Posted

I want to append a variable with the variable from a for loop. Is this even possible? I've tried this before and have spent a lot of time searching the forums for a solution.

This example doesn't work obviously but I hope it gets the idea across.
I have gui combo boxes 1 through 4. So I'm trying to take the text $Combo and append it with $foo, resulting in the text $Combo1, $Combo2, $Combo3, $Combo4
So,.. I believe it's make $combined into a string, but I want to use that in place of a Variable that matches the same text.
It would then disable the combo box 1 through 4, in this example.

For $foo = 1 To 4
    $combined = ("$Combo" & $foo)
    GUICtrlSetState($combined, $GUI_DISABLE)
Next

 

  • Solution
Posted

There are many ways to do that:

Dim $aCombo[5]

$hMain = GUICreate('Test')
For $Index = 1 To 4
    $aCombo[$Index] = GUICtrlCreateCombo('', 10, 30 * $Index + 10, 100, 20)
Next
GUISetState(@SW_SHOW, $hMain)

; We slowly disable each combo
For $Index = 1 To 4
    Sleep(1000)
    GUICtrlSetState($aCombo[$Index], 128)
Next

Do
    Sleep(10)
Until GUIGetMsg() = -3

or

$hMain = GUICreate('Test')
$cCombo1 = GUICtrlCreateCombo('', 10, 10, 100, 20)
$cCombo2 = GUICtrlCreateCombo('', 10, 40, 100, 20)
$cCombo3 = GUICtrlCreateCombo('', 10, 70, 100, 20)
$cCombo4 = GUICtrlCreateCombo('', 10, 100, 100, 20)
GUISetState(@SW_SHOW, $hMain)

;~ ; We slowly disable each combo
For $Index = 1 To 4
    Sleep(1000)
    GUICtrlSetState(Execute('$cCombo' & $Index), 128)
Next

Do
    Sleep(10)
Until GUIGetMsg() = -3

 

Posted

oh wow! it's so obvious now that I see it.
The array makes a lot of sense & I learned something new with Execute.
I did try Assign/Eval but my brain was struggling to apply it to my problem.

Thank you Andreik & Nine for the quick responses! Greatly Appreciated!

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