Subscript Dimension Error When Dynamically Creating Buttons in AutoIt -


i'm writing autoit script make gui buttons looping through array of button definitions.

it's script i'll adding/removing buttons to/from quite often, thought loop makes sense. add button handle, button text, , function name bind button array called $buttons. button parameters saved row of $buttons array pipe delimited string.

func make_buttons()      local $i = 1     local $bhandles[ubound($buttons)]     _arraydisplay($bhandles)     $button in $buttons         local $params= stringsplit($button,"|")         local $top = $i*40         local $left = 10         local $width = 100         global $bhandles[$i] = guictrlcreatebutton($params[1],$left,$top,$width)         guictrlsetonevent($bhandles[$i],$params[2])          $i = $i+1     next endfunc 

i'm getting error on execution:

global $params[1] = ^error error: missing subscript dimensions in "dim" statement

any clarifying error means appreciated.

update

@sachadee's answer below clued me along fact athat had been using global keyword declare handle variable guictrlcreatebutton() while trying use variable name. leaving off global keyword helped me eliminate error receiving. final button creation lines of code worked this:

func make_buttons()      local $i = 1     $button in $buttons         local $params= stringsplit($button,"|")         local $top = $i*40         local $left = 10         local $width = 100         global $handle = $params[2] & "_handle"         $handle = guictrlcreatebutton($params[1],$left,$top,$width)         guictrlsetonevent($handle,$params[2])         $i = $i+1     next endfunc 

edit :

you're defining array structure local $bhandles[ubound($buttons)] place [n] elements. you're not defining content of array. , you're trying redefine value global: global $bhandles[$i] = guictrlcreatebutton($params[1],$left,$top,$width).

here's better way :

#include <guiconstants.au3> #include <buttonconstants.au3>  global $allbuttons[4] = ["3","button1","button2","bouton3"]  guicreate ("title", 120, 200) $btn_start = guictrlcreatedummy() $i = 1 $allbuttons[0]     local $top = $i*40     local $left = 10     local $width = 100     guictrlcreatebutton($allbuttons[$i],$left,$top,$width) next $btn_end = guictrlcreatedummy() guisetstate ()  while 1     $msg = guigetmsg()     switch $msg         case $gui_event_close             exit         case $btn_start $btn_end             msgbox(0, "test", guictrlread($msg))     endswitch  wend 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -