Jump to content

Recommended Posts

Posted

I'm a new AutoIt user, trying to learn my way around identifying windows. I was trying to work my up to generating a list of all windows that could be found. But I hit a snag in trying to find a variable that would step through the windows.

The following code works:

Opt("WinTitleMatchMode", 4)
$WinHandle = WinGetHandle("[REGEXPTITLE:.*; INSTANCE:2]", "")
$sWinTitle = WinGetTitle($WinHandle)

It gets me the title of a window.

I presume that the RegExp will match all windows and this should get me the second entry in the list (using INSTANCE:1 gets me an empty string for the title).

But if I make the INSTANCE value a variable, it does not work.

$vInst = 2
Opt("WinTitleMatchMode", 4)
$WinHandle = WinGetHandle("[REGEXPTITLE:.*; INSTANCE:$vInst]", "")
$sWinTitle = WinGetTitle($WinHandle)

I would think that this should produce identical results to my first example, but it does not. I've pored over the Help file for about 1/2 an hour and tried searching the forum. I'm stumpted.

My alternative explanation is that you can't use a variable for an INSTANCE value, but that makes no sense. What good would the INSTANCE option be if you can't choose which one using a variable?

Can someone point me to what I've got (embarrassingly) wrong?

Thanks,

August

Posted

$vInst = 2
Opt("WinTitleMatchMode", 4)
$WinHandle = WinGetHandle("[REGEXPTITLE:.*; INSTANCE:"&$vInst&"]", "")
$sWinTitle = WinGetTitle($WinHandle)

That should solve it.

If you want to attach a variable to a string you have to use &

Posted

Thanks "blue",

You're right. It was my trying to use the variable inside the quotes that didn't work.

Obviously all the options to WinGetHandle are passed as a single string that gets parsed by the function. So I could even assemble that string outside the function call and then just pass that when it's all ready.

Also, for a newbie such as myself, still reading the scripts a character at a time, spaces around the "&" help readability:

$vInst = 2
Opt("WinTitleMatchMode", 4)
$WinHandle = WinGetHandle("[REGEXPTITLE:.*; INSTANCE:" & $vInst & "]", "")
$sWinTitle = WinGetTitle($WinHandle)

Thanks again,

August

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
×
×
  • Create New...