Jump to content

Recommended Posts

Posted

I am quite new in Autoit, so maybe this question is not very smart.

I created an array of buttons like this according to a number of parameters that the user choose in a combo box.

Dim $MyArr[$xy[1]][$xy[1]]
    For $d_2 = 0 To $xy[1] -1
        For $d_1 = 0 To $xy[1] -1
            $MyArr[$d_2][$d_2] = GUICtrlCreateButton("", 10+($d_1*22), 184+($d_2*22), 20, 20 )
            GUICtrlSetBkColor($MyArr[$d_2][$d_2], 0x604311)
        Next
    Next

My question is how do i check and start a function according to what button was pressed?

I couldn't find a way to use the $gui_msg[0] because it does not know $MyArr[$d_2][$d_2].

Please advice

Chris

Posted (edited)

Hello,

try something like this...

$numberofbuttons = 24   ;number from 1 to 30
Dim $buttoncontrolID[$numberofbuttons + 1]

GUICreate("test")
For $i = 1 To $numberofbuttons ;we make an array of buttons
    $buttoncontrolID[$i] = GUICtrlCreateButton("  Button  " & $i, 10 + ((($i > 10) + ($i > 20)) * 100), 30 + ($i - (($i > (($i > 20) + 1) * 10) * (($i > 20) + 1) * 10)) * 30,85,30)
Next
$somethingbutton=guictrlcreatebutton("do something ",310,30,80,30 )

;here you could give the buttons an other text or color
guictrlsetdata($buttoncontrolID[1] ,"Push!")
GUICtrlSetColor($buttoncontrolID[1],0xFF00FF)
guictrlsetdata($buttoncontrolID[13],"Push ME!")
GUICtrlSetColor($buttoncontrolID[13],0x000FFF)
guictrlsetdata($buttoncontrolID[17],"Push ME TOO!")
GUICtrlSetColor($buttoncontrolID[17],0xFF0000)

GUISetState()


While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case -3  ;exit is pressed
            Exit
        case $somethingbutton
            Msgbox (0,"","Button do something is pressed")

        Case $buttoncontrolID[1] To $buttoncontrolID[$numberofbuttons]   ;one of the "array"-Buttons is pressed
            call ("_arraybutton_"&($numberofbuttons-($buttoncontrolID[$numberofbuttons]-$msg)))  ;names oft the functions are _arraybutton_1() _arraybutton_2().....
            If @error = 0xDEAD And @extended = 0xBEEF Then MsgBox(4096, "ERROR", "Function "&"_arraybutton_"&($numberofbuttons-($buttoncontrolID[$numberofbuttons]-$msg))&" does not exist!")
    EndSwitch
WEnd



;*******************functions********************************
func _arraybutton_1()
    msgbox(0,"_arraybutton_"&($numberofbuttons-($buttoncontrolID[$numberofbuttons]-$msg)),"arraybutton pressed: "&GUICtrlRead($msg))
endfunc
;
; here are the funcs of the buttons
;
;
func _arraybutton_13()
    msgbox(0,"_arraybutton_"&($numberofbuttons-($buttoncontrolID[$numberofbuttons]-$msg)),"arraybutton pressed: "&GUICtrlRead($msg))
endfunc

func _arraybutton_17()
    msgbox(0,"_arraybutton_"&($numberofbuttons-($buttoncontrolID[$numberofbuttons]-$msg)),"arraybutton pressed: "&GUICtrlRead($msg))
endfunc
i hope it helps a little bit and don“t confuse you very much...

Andy

Edited by AndyG
Posted

It would be much easier to put guictrlsetonevent in your original for-next loop and use @gui_ctrlid to get the ctrlid of the button.

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...