geotau3 Posted November 30, 2016 Share Posted November 30, 2016 in other word if i have $1= GUICtrlCreateLabel("Line 1 Cell 1", 10, 30, $iWidthCell) $2 = GUICtrlCreateLabel("Line 1 Cell 1", 10, 30, $iWidthCell) $3 = GUICtrlCreateLabel("Line 1 Cell 1", 10, 30, $iWidthCell) $4 = GUICtrlCreateLabel("Line 1 Cell 1", 10, 30, $iWidthCell) how can i use it in for loop For $i = 1 to 4 GUICtrlSetData ($i,12) Next Link to comment Share on other sites More sharing options...
SadBunny Posted November 30, 2016 Share Posted November 30, 2016 (edited) Use an array for storing the handles to the created controls: GUICreate("Thingy") Dim $aLabels[4] For $i = 0 To 3 ; <-- array indices for an array dimensioned with four elements are 0-based, so they are: 0, 1, 2 and 3 $aLabels[$i] = GUICtrlCreateLabel("Line " & $i & " Cell 1", 30, 10 + $i * 30, 300) Next GUISetState() sleep(2000) For $i = 0 To 3 GUICtrlSetData($aLabels[$i], "replacement " & $i + 1) sleep (1000) Next Edited November 30, 2016 by SadBunny typo in comment Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
InunoTaishou Posted November 30, 2016 Share Posted November 30, 2016 $1= GUICtrlCreateLabel("Line 1 Cell 1", 10, 30, $iWidthCell) $2 = GUICtrlCreateLabel("Line 1 Cell 1", 10, 30, $iWidthCell) $3 = GUICtrlCreateLabel("Line 1 Cell 1", 10, 30, $iWidthCell $4 = GUICtrlCreateLabel("Line 1 Cell 1", 10, 30, $iWidthCell) For $i = 1 to 4 GUICtrlSetData(Eval($i), 12) Next Or Global $hDummyStartLabels = GUICtrlCreateDummy() $1= GUICtrlCreateLabel("Line 1 Cell 1", 10, 30, $iWidthCell) $2 = GUICtrlCreateLabel("Line 1 Cell 1", 10, 30, $iWidthCell) $3 = GUICtrlCreateLabel("Line 1 Cell 1", 10, 30, $iWidthCell $4 = GUICtrlCreateLabel("Line 1 Cell 1", 10, 30, $iWidthCell) Global $hDummyEndLabels = GUICtrlCreateDummy() For $i = $hDummyStartLabels + 1 to $hDummyEndLabels - 1 GUICtrlSetData($i, 12) Next Link to comment Share on other sites More sharing options...
BrewManNH Posted November 30, 2016 Share Posted November 30, 2016 (edited) This is very simple and doesn't require using Eval. $1 = GUICtrlCreateLabel("Line 1 Cell 1", 10, 30, $iWidthCell) $2 = GUICtrlCreateLabel("Line 1 Cell 1", 10, 30, $iWidthCell) $3 = GUICtrlCreateLabel("Line 1 Cell 1", 10, 30, $iWidthCell) $4 = GUICtrlCreateLabel("Line 1 Cell 1", 10, 30, $iWidthCell) ; how can i use it In For loop For $i = $1 To $4 GUICtrlSetData($i, 12) Next Edited November 30, 2016 by BrewManNH If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
SadBunny Posted November 30, 2016 Share Posted November 30, 2016 That works, but it leads to shaky code as its functionality will depend on the order in which the labels are created in the code, and whether or not there's any other things created in between those assignments. Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
BrewManNH Posted November 30, 2016 Share Posted November 30, 2016 The whole script is shaky to start with. Your script would work identically to what I wrote. You're building the controls in the exact same order that I am, you're just assigning the control IDs to an array element instead of simple variables. Control IDs in an array are equally dependent upon order of creation when building them in a loop. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
SadBunny Posted November 30, 2016 Share Posted November 30, 2016 Agreed, it would work identically, but once it grows and grows and grows like these scripts have a tendency to do, your approach is easier to break, e.g. if you intersperse the labels with inputs, buttons and other controls. Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
BrewManNH Posted December 1, 2016 Share Posted December 1, 2016 Then don't do that, it's not that hard to avoid stupid mistakes once you know what you're doing. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
SadBunny Posted December 1, 2016 Share Posted December 1, 2016 I won't. But TS might, and then wonder what the * is going on Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
geotau3 Posted December 2, 2016 Author Share Posted December 2, 2016 thanks but what if the variable contain more than number $GSa1 , $GSa2, $GSa3, $GSa4 Link to comment Share on other sites More sharing options...
InunoTaishou Posted December 2, 2016 Share Posted December 2, 2016 Then you can store the handles in an array, use eval if that's how your variables are formatted, or use Brew's method $GSa1= GUICtrlCreateLabel("Line 1 Cell 1", 10, 30, $iWidthCell) $GSa2 = GUICtrlCreateLabel("Line 1 Cell 1", 10, 30, $iWidthCell) $GSa3 = GUICtrlCreateLabel("Line 1 Cell 1", 10, 30, $iWidthCell $GSa4 = GUICtrlCreateLabel("Line 1 Cell 1", 10, 30, $iWidthCell) $aLabels[] = [$GSa1, $GSa2, $GSa3, $GSa4] For $i = 1 to 4 GUICtrlSetData(Eval("GSa" & $i), 12) Next For $i = $GSa1 to $GSa4 GUICtrlSetData($i, 12) Next For $i = 0 to UBound($aLabels) - 1 GUICtrlSetData($aLabels[$i], 12) Next Link to comment Share on other sites More sharing options...
kylomas Posted December 2, 2016 Share Posted December 2, 2016 geotau3, When defining groups of variables it is always better to define them in a loop and store the ctlids in an array (post #2). @InunoTaishou - I've looked at your code. I know you would never write goobledeegook like that. I think it is generally good to offer alternative ways of approaching problem, however, given this users relative inexperience I would stay away from "eval", "assign", "execute", etc. $.02 kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now