Jump to content

Passing the button instance through a variable in ControlClick


Recommended Posts

hi,

I am new to Autoit and was wondering how to pass the button instance parameter as a variable in ControlClick. I need to read the button instance from a file (e.g. 5), store it in a variable and then need controlclick to click on that button instance. I tried concatenation something like this :

$firstnum = "[CLASS:Button; INSTANCE:" & $instanceVariable & "]"

ControlClick($hWnd3, "", $firstnum)

It does not work and throws error in the first line saying illegal format. Please help me regarding this. Thanks in advance

Link to comment
Share on other sites

Good attempt, look up ControlGetHandle() in the help file.

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

This example appears to work.

Run("calc.exe")

WinWaitActive("Calculator")
Local $hWnd3 = WinGetHandle("Calculator")

Local $instanceVariable = 42 ; Button42 is button 7 on calculator.

Local $firstnum = "[CLASSNN:Button" & $instanceVariable & "]"
ControlClick($hWnd3, "", $firstnum)
; or
$firstnum = "[Class:Button; Instance:" & $instanceVariable & "]"
ControlClick($hWnd3, "", $firstnum)
; or
$firstnum = "Button" & $instanceVariable
ControlClick($hWnd3, "", $firstnum)

Edit: Added the last example of using the ClassnameNN property of the control as the controlID parameter in the ControlClick() function.

Edited by Malkey
Link to comment
Share on other sites

I'd suggest outputting the concatenated string via a MsgBox to see what is actually passed as a parameter to ControlClick. Since you mentioned reading some data from a file and storing that into a variable, I'm guessing that the error may lie with the data you read and/or the way you handled that data.

Link to comment
Share on other sites

I would do something like this

Global Const $appHandle = WinGetHandle("[ACTIVE]")

Local $bHandle = ControlGetHandle($appHandle, "", "[Class:Button; Instance:" & $instanceVariable & "]")
If $bHandle == "" Then
    MsgBox(0, "Handle Error", "button handle not obtained")
EndIf

ControlClick($bHandle, "", "")

Safer code.

Edited by bo8ster

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

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