Jump to content

Lots of bottons without giving all the same function...


Recommended Posts

Hello.

I have 100 bottons, named from 1x1 to 1x10 to 10x10...

Is there anyway I can give them all the same function without having to writing a function to all of them.

What I would like to avoid was...:

While 1
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $1x1
            $mycode

...

        Case $1x10
            $mycode

...

        Case $10x10
            $mycode
    EndSwitch
WEnd

... all the way through.

Hope someone understands. :)

// Vossen

Link to comment
Share on other sites

Give your buttons the same variable and have that variable trigger the function.

Problem solved.
That will only work with the last created button.

You'll have to do something like this:

Global $Buttons[100]

$Button[0] = guictrlcreatebutton("1x1",10,10,120,23)
...

While 1

$nMsg = Guigetmsg()

for $i = 0 to 100

if $nMsg = $Button[$i] Then
; your function
endif

next

WEnd
Edited by Kip
Link to comment
Share on other sites

I see, minor problem with my explanation.

Okay, the functions needs to be slightly different.

I would like it to be like, when I press '5x2' the text should change from N to Y.

Like this:

NNNNNNNNNN

NNNNNNNNNN

NNNNNNNNNN

NNNNNNNNNN

NNNNNNNNNN

When I press '5x2' it should change to:

NNNNNNNNNN

NNNNNNNNNN

NNNNNNNNNN

NNNNNNNNNN

NYNNNNNNNN

EDIT: Thanks Kip, will try that!

Edited by Vossen
Link to comment
Share on other sites

That gives an error Kip

$Button = GUICtrlCreateButton(...)

$Button^ERROR

Error: Expected a "=" operator in assignment statement.

Any ideas?

EDIT: Found the problem, Global $Buttons[100], my vars was $Button. Thanks for the help!

Edited by Vossen
Link to comment
Share on other sites

I haven't tested this, but give it a shot

While
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE ExitLoop
            
    For $i = 0 To 99 Step 1
        If $msg = $button[$i] _cLabel(GUICtrlRead($button[$i]),$button[$i])
    Next
        
WEnd
...
Func _cLabel($name,$btn)
    If $name = "N" Then GUICtrlSetData ($btn,"Y")
    If $name = "Y" Then GUICtrlSetData ($btn,"N")
EndFunc
Edited by aslani

[font="Georgia"]Chances are, I'm wrong.[/font]HotKey trouble?Stringregexp GuideAutoIT Current Version

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...