Jump to content

CASE Button with Array. Possible?


 Share

Recommended Posts

Hi all,

I created a gui with several (dynamic) buttons:

Func _create_Input()
    $Alto = 165
    $Sinistra = 176
    $delta = 0
    $multiplier = 0
    local $a, $t
    For $t = 0 To 24
        For $a = 0 To 12
            $InputBLD[$t][$a] = GUICtrlCreateButton("", $Sinistra + $delta * $multiplier, $Alto, 50, 21, BitOR($ES_READONLY,$ES_CENTER))
            $delta = 55
            $multiplier = $multiplier + 1
            GUICtrlSetState($InputBLD[$t][$a],$GUI_HIDE)
        Next
        $Alto = $Alto + 25
        $delta = 0
        $multiplier = 0
    Next
EndFunc

Now i Have 13x25 buttons, hidden (for faster loading. Only needed rows will be shown later if needed)

Let's say I have only 2 rows:

$InputBLD[0][0]....to [12]
$InputBLD[1][0]....to [12]

for a total of 26 buttons.

Is there a way to do actions without declaring before all of them?

I mean, i'm looking to do something like:

case $InputBLD[$h][$v]
   do something

instead of declaring

global $InputBLD[0][0],$InputBLD[0][1],$InputBLD[0][2],...,$InputBLD[24][13]

I tried and it didn't work (as expected).

Thanks a lot,

Marco

Link to comment
Share on other sites

If you are declaring them one after the other (as it looks like you are), then the id's for the controls will be consecutive numbers. We can use this to speciafy a range. For example, if you make a GUI with twelve buttons (and no other controls) starting from an id of 1 (I'm not suire where they start from) then the buttons will be all the id's in the range 1 to 12.

For the case this is simple:

Case $iFirst To $iLast

Using arrays doesn't change that.

Case $InputBLD[0][0] To $InputBLD[$h][$v]

Try it. I'm not guarenteeing anything here as this is more of a workaround, If you are unsure then the last thing to do is use the "Case Else" and go through a loop:

$iMsg = GUIGetMsg()
Switch $iMsg
    Case ... ; Normal Case statements
    Case Else
        For $x = 0 to $h
            For $y = 0 to $v
                If $iMsg = $InputBLD[$x][$y] Then
                    do domething
                EndIf
            Next
        Next
EndSwitch

That is a foolproof method, but if you are working with a lot of buttons then it may be a bit slow, and may not look particularly pretty.

I hope that somewhere there is the answer :graduated:

Mat

Link to comment
Share on other sites

Global $aButtons[10][10]

$hWnd = GUICreate("")

For $y = 0 To UBound($aButtons) - 1
    For $x = 0 To UBound($aButtons, 2) - 1
        $aButtons[$y][$x] = GUICtrlCreateButton("", $x * 20, $y * 20, 20, 20)
    Next
Next

GUISetState()
While 1
    $iMsg = GUIGetMsg()
    Switch $iMsg
    Case -3
        Exit

    Case $aButtons[0][0] To $aButtons[UBound($aButtons) - 1][UBound($aButtons, 2) - 1]
        For $_y = 0 To UBound($aButtons) - 1
            For $_x = 0 To UBound($aButtons, 2) - 1
                If ($iMsg = $aButtons[$_y][$_x]) Then
                    MsgBox(0, "", "Button: " & $_y & ", " & $_x & " was pressed!")
                EndIf
            Next
        Next
    EndSwitch
WEnd

I'm at work, so I can't test this. This is hardcoded from my head. :graduated:

Try something like this.

EDIT: Typo

Edited by AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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