Sign in to follow this  
Followers 0
myuncleian

Use of ByRef with GUI controls

3 posts in this topic

First post. For a scripting language, AutoIt is a great development tool :whistle:

If I have a GUI label ($label1) and wish to change the font I can say:

GUICtrlSetFont($label1, -1, -1, -1, "Lucida Console")

I can put this in a function and call it:

ChangeFont($label1)

Func ChangeFont(ByRef $nameofctrl)
    GUICtrlSetFont($nameofctrl, -1, -1, -1, "Lucida Console")
EndFunc

So, if I have more than one label ($label1, $label2, $label3, ...) I want to say:

For $i = 1 to 10
    ChangeFont("$label" & $i)
Next

But it seems I can't pass a control (as a string) into the function. How do I do this without having to say:

ChangeFont($label1)
ChangeFont($label2)
ChangeFont($label3)
...

Share this post


Link to post
Share on other sites



You could consider Eval() for passing the string. The variables would need to be seen to use this example.

$controlhandle1 = 'handle1'
$controlhandle2 = 'handle2'
ChangeFont('controlhandle')

Func ChangeFont($string_eval)
    For $i = 1 To 2
        MsgBox(0, '', Eval($string_eval & $i))
    Next
EndFunc

:whistle:

Share this post


Link to post
Share on other sites

Many thanks MHz, I'll try that.

I've just found out that I can put controls in arrays so it's probably easier to put all my labels in an array.

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