mcclane654 Posted November 24, 2013 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?
water Posted November 24, 2013 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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
mcclane654 Posted November 24, 2013 Author Posted November 24, 2013 yes of course (facepalm) thx water
Rogue5099 Posted November 24, 2013 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
monax Posted November 24, 2013 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
Rogue5099 Posted November 25, 2013 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
akorx Posted May 20, 2014 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
water Posted May 20, 2014 Posted May 20, 2014 That's what arrays are being made for. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
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