Sign in to follow this  
Followers 0
Vossen

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

7 posts in this topic

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

So instead of $1x1 - $10x10, just use $button on all of them.

Problem solved.

Edited by aslani

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

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

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

Share this post


Link to post
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
Sign in to follow this  
Followers 0