Sunaj Posted October 7, 2006 Share Posted October 7, 2006 Hi, I've been trying to do dynamic initialization of variables with autoit.. like so: .... $i = 1 While $i <= UBound($SomeArray) - 1 $Menu & $i = GUICtrlCreateMenuItem($SomeArray[$i], $OptionsContext) GUICtrlSetOnEvent ($Menu & $i,"Hotkey" & $i) $i = $i + 1 WEnd .... This is obviously not working - but are there any hacks that could achieve dynamic variable initiation? [list=1][*]Generic way to detect full path to default browser, List/ListView Events Using GuiRegisterMsg (detect doubleclick and much more)[*]Using dllcall for full control over fileopendialog, Make DirMove act somewhat normally (by circumventing it...)[*]Avoid problems with "&" (chr(38)) in code, Change desktop maximized area/workspace (fx to make deskbar type app)[*]Change focus behavior when buttons are clicked to work closer to 'standard windows' app[*](Context) Menus With Timed Tooltips, Fast Loops & Operators in AU3[*]Clipboard UDF, A clipboard change notification udf[/list] Link to comment Share on other sites More sharing options...
/dev/null Posted October 7, 2006 Share Posted October 7, 2006 Hi, I've been trying to do dynamic initialization of variables with autoit.. like so: .... $i = 1 While $i <= UBound($SomeArray) - 1 $Menu & $i = GUICtrlCreateMenuItem($SomeArray[$i], $OptionsContext) GUICtrlSetOnEvent ($Menu & $i,"Hotkey" & $i) $i = $i + 1 WEnd .... This is obviously not working - but are there any hacks that could achieve dynamic variable initiation? make $Menu an array. Cheers Kurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
Sunaj Posted October 7, 2006 Author Share Posted October 7, 2006 Thanks f quick reply - unfortunately DIM'ing menu as an array produces the following errors: ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: $Menu[$i] = GUICtrlCreateMenuItem($SomeArray[$i], $OptionsContext) ^ ERROR make $Menu an array. Cheers Kurt [list=1][*]Generic way to detect full path to default browser, List/ListView Events Using GuiRegisterMsg (detect doubleclick and much more)[*]Using dllcall for full control over fileopendialog, Make DirMove act somewhat normally (by circumventing it...)[*]Avoid problems with "&" (chr(38)) in code, Change desktop maximized area/workspace (fx to make deskbar type app)[*]Change focus behavior when buttons are clicked to work closer to 'standard windows' app[*](Context) Menus With Timed Tooltips, Fast Loops & Operators in AU3[*]Clipboard UDF, A clipboard change notification udf[/list] Link to comment Share on other sites More sharing options...
The Kandie Man Posted October 7, 2006 Share Posted October 7, 2006 (edited) dim $Menu[1] $i = 1 While $i <= UBound($SomeArray) - 1 $Menu[$i - 1] = GUICtrlCreateMenuItem($SomeArray[$i], $OptionsContext) GUICtrlSetOnEvent ($Menu[$i - 1],"Hotkey" & $i) $i = $i + 1 ReDim $Menu[$i] WEnd Does that work? Edited October 7, 2006 by The Kandie Man "So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire Link to comment Share on other sites More sharing options...
Sunaj Posted October 7, 2006 Author Share Posted October 7, 2006 Dude - seriously thanks a lot! - had resorted to static initialization which is just a bad solution... now its all working perfectly. Cheers dim $Menu[1] $i = 1 While $i <= UBound($SomeArray) - 1 $Menu[$i - 1] = GUICtrlCreateMenuItem($SomeArray[$i], $OptionsContext) GUICtrlSetOnEvent ($Menu[$i - 1],"Hotkey" & $i) $i = $i + 1 ReDim $Menu[$i] WEnd Does that work? [list=1][*]Generic way to detect full path to default browser, List/ListView Events Using GuiRegisterMsg (detect doubleclick and much more)[*]Using dllcall for full control over fileopendialog, Make DirMove act somewhat normally (by circumventing it...)[*]Avoid problems with "&" (chr(38)) in code, Change desktop maximized area/workspace (fx to make deskbar type app)[*]Change focus behavior when buttons are clicked to work closer to 'standard windows' app[*](Context) Menus With Timed Tooltips, Fast Loops & Operators in AU3[*]Clipboard UDF, A clipboard change notification udf[/list] Link to comment Share on other sites More sharing options...
PsaltyDS Posted October 7, 2006 Share Posted October 7, 2006 (edited) Hi, I've been trying to do dynamic initialization of variables with autoit.. like so: .... $i = 1 While $i <= UBound($SomeArray) - 1 $Menu & $i = GUICtrlCreateMenuItem($SomeArray[$i], $OptionsContext) GUICtrlSetOnEvent ($Menu & $i,"Hotkey" & $i) $i = $i + 1 WEnd .... oÝ÷ Ù8b²+(nø¨ºÉrp¢¹"޶«y©ò§$²ØZµÊ.Ö'¯yܧjh½ªâi¹^x«b¢êº^bjw+y«^½ªâi¹^³v¦zÇ+y«^v)춸§^«b¢{-ç(f§vÆ«x, ÚÑ/jPn¶)ÚÉæ«¢{aÇè®éÙ*h²Û(Øb²Ú)ÉènrÉëajÇ(ë©Â+aj (v·²ß¢·hx-+"Ë^iÚjv«¬*.«Þmæ«çZ®¶²³'v("Ü"Yç¯z¼)àÊ£X¬¶Êu«Zy«"z¶§vj+zËZnW¢Ø^~ënàèÛaÌË©Ú®¶²jëh×6; Include statement at the top of your script #include <array.au3> Dim $aMenu[1] For $i = 1 To UBound($SomeArray) - 1 _ArrayAdd($aMenu, GUICtrlCreateMenuItem($SomeArray[$i], $OptionsContext)) GUICtrlSetOnEvent ($aMenu[$i] ,"Hotkey" & $i) Next $aMenu[0] = Ubound($aMenu) - 1oÝ÷ Øíz»ay¦è½ç(uë'^¶»§³*.«Þjv«¬¨~ö«¦åzW§Øm«¢{Z{-à®R²íéèzk4ߦz{´ríj)춢éí¡ûhµ©fz{¢µé¬âÓ~1éîÖØk»Múhǧº)ÿÊ'µ¨§¶¢{k¢R°Z+y§!éîצjw¯z{_ºw-è|z-쵶îd{(§þ(Z±·ÇN,yû§rبÌ"XZ½ëhmç^rV«yÜ!Èjyèµ·¢w¢©h¢(ʦmÁ©í¶Þ¶§ØZ¶Ëkj× É.r¥v"Ûazf¥Ú(ãâ-zgîËb¢v§v+pYd0'!¢w°jËç-yÖò¶PD²§+¡«¢+Øì%¹±ÕÍÑѵ¹ÐÐѡѽÀ½å½ÕÈÍÉ¥ÁÐ(¥¹±Õ±ÐíÉÉä¹ÔÌÐì((ìQ¡¥ÉÍÐÁÉнå½ÕÈÍÉ¥Áи¸¸()¥´ÀÌØí5¹ÕlÅt)½ÈÀÌØí¤ôÄQ¼U ½Õ¹ ÀÌØíM½µÉÉ䤴Ä(%}ÉÉå ÀÌØí5¹Ô°U% Ñɱ ÉÑ5¹Õ%Ñ´ ÀÌØíM½µÉÉålÀÌØí¥t°ÀÌØí=ÁÑ¥½¹Í ½¹ÑáФ($ì ¡¹Ñ¡½±±½Ý¥¹±¥¹¥¹Í¥Ñ¡½È±½½À¸¸¸(%U% ÑɱMÑ=¹Ù¹Ð ÀÌØí5¹ÕlÀÌØí¥t°ÅÕ½Ðí}5¹Õ%Ñ´ÅÕ½ÐìµÀìÀÌØí¤¤)9áÐ(ÀÌØí5¹ÕlÁtôU½Õ¹ ÀÌØí5¹Ô¤´Ä((ìQ¡ÉÍнå½ÕÈÍÉ¥Áи¸¸((ì1½°Õ¹Ñ¥½¸½Èͱѥ¹µ¹Ô¥Ñ´)Õ¹}5¹Õ%Ñ´ ¤(%1½°ÀÌØí¤°ÀÌØí Ñɱ9Õ´ôU%} QI1%(%½ÈÀÌØí¤ôÄQ¼ÀÌØí5¹ÕlÁt($%%ÀÌØí5¹ÕlÀÌØí¥tôÀÌØí Ñɱ9Õ´Q¡¸($$%5Í ½à ØаÅÕ½Ðí5¹Õ%Ñ´ÅÕ½Ðì°ÅÕ½Ðíe½Ôͱѵ¹Ô¥Ñ´¹¼¸ÅÕ½ÐìµÀìÀÌØí¤µÀìÅÕ½Ðì°Ý¥Ñ ½¹Ñɽ°%ÅÕ½ÐìµÀìÀÌØí Ñɱ9Õ´µÀìÅÕ½Ðì¸ÅÕ½Ðì¤($$%IÑÕɸ($%¹%(%9áÐ)¹Õ¹ Cheers! Edit: Replaced missing close-paren per Sunaj. Edited October 10, 2006 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Sunaj Posted October 7, 2006 Author Share Posted October 7, 2006 Hi PsaltyDS; this looks very promising - also easier to understand the code in this way..! I am already using arrays f a lot of other data in my prg but just had trouble when it came to using them for GUICtrlCreate's (the way I did it caused errors..etc). Well, with the code below I can see that those are troubles of the past - will do implementation of this new code tomorrow. Will report back on progress, very good and easy to grasp posting you made. Thanks You can create variables with names created in string operations, the commands are Assign() and Eval(). But in a year on this forum, and many posts on this topic, nobody yet has come up with a good reason for doing this instead of an array. If you haven't learned arrays yet, do so. It will make everything you do with lists of data easier and more stable in the future. Do it this way with an array: ; Include statement at the top of your script #include <array.au3> Dim $aMenu[1] For $i = 1 To UBound($SomeArray) - 1 _ArrayAdd($aMenu, GUICtrlCreateMenuItem($SomeArray[$i], $OptionsContext) GUICtrlSetOnEvent ($aMenu[$i] ,"Hotkey" & $i) Next $aMenu[0] = Ubound($aMenu) - 1oÝ÷ Øíz»ay¦è½ç(uë'^¶»§³*.«Þjv«¬¨~ö«¦åzW§Øm«¢{Z{-à®R²íéèzk4ߦz{´ríj)춢éí¡ûhµ©fz{¢µé¬âÓ~1éîÖØk»Múhǧº)ÿÊ'µ¨§¶¢{k¢R°Z+y§!éîצjw¯z{_ºw-è|z-쵶îd{(§þ(Z±·ÇN,yû§rبÌ"XZ½ëhmç^rV«yÜ!Èjyèµ·¢w¢©h¢(ʦmÁ©í¶Þ¶§ØZ¶Ëkj× É.r¥v"Ûazf¥Ú(ãâ-zgîËb¢v§v+pYd0'!¢w°jËç-yÖò¶PD²§+¡«¢+Øì%¹±ÕÍÑѵ¹ÐÐѡѽÀ½å½ÕÈÍÉ¥ÁÐ(¥¹±Õ±ÐíÉÉä¹ÔÌÐì((ìQ¡¥ÉÍÐÁÉнå½ÕÈÍÉ¥Áи¸¸()¥´ÀÌØí5¹ÕlÅt)½ÈÀÌØí¤ôÄQ¼U ½Õ¹ ÀÌØíM½µÉÉ䤴Ä(%}ÉÉå ÀÌØí5¹Ô°U% Ñɱ ÉÑ5¹Õ%Ñ´ ÀÌØíM½µÉÉålÀÌØí¥t°ÀÌØí=ÁÑ¥½¹Í ½¹ÑáФ($ì ¡¹Ñ¡½±±½Ý¥¹±¥¹¥¹Í¥Ñ¡½È±½½À¸¸¸(%U% ÑɱMÑ=¹Ù¹Ð ÀÌØí5¹ÕlÀÌØí¥t°ÅÕ½Ðí}5¹Õ%Ñ´ÅÕ½ÐìµÀìÀÌØí¤¤)9áÐ(ÀÌØí5¹ÕlÁtôU½Õ¹ ÀÌØí5¹Ô¤´Ä((ìQ¡ÉÍнå½ÕÈÍÉ¥Áи¸¸((ì1½°Õ¹Ñ¥½¸½Èͱѥ¹µ¹Ô¥Ñ´)Õ¹}5¹Õ%Ñ´ ¤(%1½°ÀÌØí¤°ÀÌØí Ñɱ9Õ´ôU%} QI1%(%½ÈÀÌØí¤ôÄQ¼ÀÌØí5¹ÕlÁt($%%ÀÌØí5¹ÕlÀÌØí¥tôÀÌØí Ñɱ9Õ´Q¡¸($$%5Í ½à ØаÅÕ½Ðí5¹Õ%Ñ´ÅÕ½Ðì°ÅÕ½Ðíe½Ôͱѵ¹Ô¥Ñ´¹¼¸ÅÕ½ÐìµÀìÀÌØí¤µÀìÅÕ½Ðì°Ý¥Ñ ½¹Ñɽ°%ÅÕ½ÐìµÀìÀÌØí Ñɱ9Õ´µÀìÅÕ½Ðì¸ÅÕ½Ðì¤($$%IÑÕɸ($%¹%(%9áÐ)¹Õ¹ Cheers! [list=1][*]Generic way to detect full path to default browser, List/ListView Events Using GuiRegisterMsg (detect doubleclick and much more)[*]Using dllcall for full control over fileopendialog, Make DirMove act somewhat normally (by circumventing it...)[*]Avoid problems with "&" (chr(38)) in code, Change desktop maximized area/workspace (fx to make deskbar type app)[*]Change focus behavior when buttons are clicked to work closer to 'standard windows' app[*](Context) Menus With Timed Tooltips, Fast Loops & Operators in AU3[*]Clipboard UDF, A clipboard change notification udf[/list] Link to comment Share on other sites More sharing options...
sulfurious Posted October 7, 2006 Share Posted October 7, 2006 You can create variables with names created in string operations, the commands are Assign() and Eval(). But in a year on this forum, and many posts on this topic, nobody yet has come up with a good reason for doing this instead of an array.Actually I found a very good reason to use the Assign() and Eval() commands.http://www.autoitscript.com/forum/index.php?showtopic=33815I have an array that has the same name for a group of items. The array can change but the name could still exist for a different set of items. I used it to populate a TreeView control. It allowed me to assign the control a name that could exist again. I think I used it correctly anyway.later,Sul Link to comment Share on other sites More sharing options...
PsaltyDS Posted October 7, 2006 Share Posted October 7, 2006 Actually I found a very good reason to use the Assign() and Eval() commands.http://www.autoitscript.com/forum/index.php?showtopic=33815I have an array that has the same name for a group of items. The array can change but the name could still exist for a different set of items. I used it to populate a TreeView control. It allowed me to assign the control a name that could exist again. I think I used it correctly anyway.later,SulNice function! Having extracted your depth in $mLEN, however, I think you can derive from that exactly how many strings or array elements it will take to describe the complete tree. You have certainly shown excellent use of Assign() and Eval(), but I think it could be done with arrays. I'll give it a shot when I get some time on a Windows box.That doesn't change the fact that you have a working function already that shows clean use of those tools. Nice job. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
sulfurious Posted October 8, 2006 Share Posted October 8, 2006 Thank you. The one thing I woudl improve upon is the amount of time it takes to walk through the directory chosen. A simple program file directory is not bad, but a large directory with many subdirectories is somewhat slow. later, Sul Link to comment Share on other sites More sharing options...
Sunaj Posted October 9, 2006 Author Share Posted October 9, 2006 Ups .. slow reply on this one: got everything to work as intended! For anyone wanting to use the nice example posted by PsaltyDS there's a missing ")" in this line. .... _ArrayAdd($aMenu, GUICtrlCreateMenuItem($SomeArray[$i], $OptionsContext)) ; fixed here .... Thanks f all the inputs to this post [list=1][*]Generic way to detect full path to default browser, List/ListView Events Using GuiRegisterMsg (detect doubleclick and much more)[*]Using dllcall for full control over fileopendialog, Make DirMove act somewhat normally (by circumventing it...)[*]Avoid problems with "&" (chr(38)) in code, Change desktop maximized area/workspace (fx to make deskbar type app)[*]Change focus behavior when buttons are clicked to work closer to 'standard windows' app[*](Context) Menus With Timed Tooltips, Fast Loops & Operators in AU3[*]Clipboard UDF, A clipboard change notification udf[/list] Link to comment Share on other sites More sharing options...
PsaltyDS Posted October 10, 2006 Share Posted October 10, 2006 For anyone wanting to use the nice example posted by PsaltyDS there's a missing ")" in this line. _ArrayAdd($aMenu, GUICtrlCreateMenuItem($SomeArray[$i], $OptionsContext)) ; fixed here DOH! Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law 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