Jump to content

Accessing a control using variables to build the ID


Go to solution Solved by Nine,

Recommended Posts

Posted

I have 5 input boxes labeled $hEdit1 through $hEdit5 that represent slots. I pull a report file whose name contains the slot the file comes from. I'm parsing the filename to get the actual slot and then changing the background color of the appropriate input box to show visually where it came from. I can change the background color directly with GUICtrlSetBkColor($hEdit2, 0x00FF00) for example with no problem and  _ArrayDisplay shows me my slot variable is correct. I combined the two like this GUICtrlSetBkColor("$hEdit" & $Slot, 0x00FF00) and I get no error but it wont change the background. When I combine "$hEdit" & $Slot in a message box it shows $hEdit2 as expected. I'm sure I'm missing something simple here but my searches haven't found anything explaining this. Can Anyone explain why this doesn't work for identifying the control? 

  • Solution
Posted

That was way harder than I expected but it did work. I guess it wasnt able to build it  on the fly but building and eval'ing the string first was able to work. I ended up with Something like this;  $combined = "hEdit" &  $Slot then $evaled = eval($combined) then finally GUICtrlSetBkColor($evaled, 0x00FF00). I could not find a way to do it inside the GUICtrlSetBkColor directly but it does work.

Posted

Just for an alternative, you also have:

Execute("GUICtrlSetBkColor(" & "$hEdit" &  $Slot & ", 0x00FF00)")

Or:

GUICtrlSetBkColor(Eval("hEdit" &  $Slot), 0x00FF00)

Best regards,

Donny

LibreOffice UDF  

Scite4AutoIt Spell-Checker Using LibreOffice

WPS Office adapter — Use MS Word UDFs with WPS Office!

LibreOffice API Inspector tools

Spoiler

"Life is chiefly made up, not of great sacrifices and wonderful achievements, but of little things. It is oftenest through the little things which seem so unworthy of notice that great good or evil is brought into our lives. It is through our failure to endure the tests that come to us in little things, that the habits are molded, the character misshaped; and when the greater tests come, they find us unready. Only by acting upon principle in the tests of daily life can we acquire power to stand firm and faithful in the most dangerous and most difficult positions."

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
×
×
  • Create New...