mcclane654 Posted November 24, 2013 Share Posted November 24, 2013 Local $counter = 0 While $counter < 5 $var$counter = 1+$counter $counter=$counter+1 WEnd GUICreate("test") GUISetState() GUICtrlCreateLabel($var0, 5, 20) GUICtrlCreateLabel($var1, 5, 40) GUICtrlCreateLabel($var2, 5, 60) GUICtrlCreateLabel($var3, 5, 80) GUICtrlCreateLabel($var4, 5, 100) i would like my $var to have the counter number added to its name. is this even possible if it is how? Link to comment Share on other sites More sharing options...
water Posted November 24, 2013 Share Posted November 24, 2013 Using arrays makes it much easier than adding the index to the variable name. Means: Use $var[0] instead of $var0. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
mcclane654 Posted November 24, 2013 Author Share Posted November 24, 2013 yes of course (facepalm) thx water Link to comment Share on other sites More sharing options...
Rogue5099 Posted November 24, 2013 Share Posted November 24, 2013 Does this help at all? Local $var[1], $counter = 0 While $counter < 5 $var[$counter] = 1 + $counter $counter = $counter + 1 ReDim $var[UBound($var) + 1] WEnd GUICreate("test") GUISetState(@SW_SHOW) For $i = 0 To $counter GUICtrlCreateLabel($var[$i], 5, 20 * $i) Next My projects: Inventory / Mp3 Inventory, Computer Stats Link to comment Share on other sites More sharing options...
monax Posted November 24, 2013 Share Posted November 24, 2013 Does this help at all? Local $var[1], $counter = 0 While $counter < 5 $var[$counter] = 1 + $counter $counter = $counter + 1 ReDim $var[UBound($var) + 1] WEnd GUICreate("test") GUISetState(@SW_SHOW) For $i = 0 To $counter GUICtrlCreateLabel($var[$i], 5, 20 * $i) Next Maybe Im wrong, but i think changing an array size inside a loop is a not a good thing. Instead it should create at start an array with the final size. If the amount of elements that will be assigned to the array is unknow before run the program, then you should use a guess value for the array size and after the loop use the ReDim to reduce the array size. In this case the final size is know, so the code could be: $max = 5 Local $var[$max], $counter = 0 While $counter < $max $var[$counter] = 1 + $counter $counter += 1 WEnd GUICreate("test") GUISetState(@SW_SHOW) For $i = 0 To $counter-1 GUICtrlCreateLabel($var[$i], 5, 20 * $i) Next sleep(3000) ;Time to see the GUI before the program end Link to comment Share on other sites More sharing options...
Rogue5099 Posted November 25, 2013 Share Posted November 25, 2013 If the amount of elements that will be assigned to the array is unknow before run the program, then you should use a guess value for the array size and after the loop use the ReDim to reduce the array size. This "guessing" the size of an unknown array could cause for a "Array variable has incorrect number of subscripts or subscript dimension range exceeded" error and that could lead to it not working at all. There is nothing wrong with re-sizing an array within a loop. If there is a known amount then you could set the size at the beginning and not use another variable as follows: Local $var[6], $counter = 0 While $counter < UBound($var) - 1 $var[$counter] = 1 + $counter $counter += 1 WEnd GUICreate("test") GUISetState(@SW_SHOW) For $i = 0 To $counter GUICtrlCreateLabel($var[$i], 5, 20 * $i) Next My projects: Inventory / Mp3 Inventory, Computer Stats Link to comment Share on other sites More sharing options...
akorx Posted May 20, 2014 Share Posted May 20, 2014 (edited) Is there a way to create directly the name of the variables in loop ? like something like that "dim $p$i" where $i increase each time ? Edited May 20, 2014 by akorx AkorxMail akorx@yahoo.fr Link to comment Share on other sites More sharing options...
water Posted May 20, 2014 Share Posted May 20, 2014 That's what arrays are being made for. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki 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