Strings and %'s and .'s

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
EvoWing
Posts: 1
Joined: 27 Jul 2014, 06:11

Strings and %'s and .'s

27 Jul 2014, 09:05

Hi,

I really can't get my head around the use of %'s.
I'm a C and C++ (amongst others) programmer for 37 years but have difficulty with AHK variables.
Pretty much got it sorted now except for ....

Finding a window works fine until I search for a window with a "." in the desired string..

Code: Select all

SetTitleMatchMode, 2
MyTitle := "Calculator"
IfWinExist %MyTitle%
but

Code: Select all

SetTitleMatchMode, 2
MyTitle := "192.168.1.123"
IfWinExist %MyTitle%
gives
"Exception Thrown"...."The following variable name contains an illegal character:"....

Code: Select all

SetTitleMatchMode, 2
MyTitle := "123"
IfWinExist %MyTitle%
Works just fine.

Is this an implicit use of RegEx by AHK?
If that's the case, then can I disable it as I use the same variable elsewhere and don't really want to have a second variable with the necessary RegEx format?

Rod.
dens20
Posts: 4
Joined: 26 Jul 2014, 17:15

Re: Strings and %'s and .'s

27 Jul 2014, 10:51

I did c/p your middle code and run ( win7, AHKA32 v1.1.15.02). No exception, it works. Maybe there is something in the environment u're running ?
lexikos
Posts: 9690
Joined: 30 Sep 2013, 04:07
Contact:

Re: Strings and %'s and .'s

27 Jul 2014, 21:10

I would guess that the example you gave is not the actual code you were using.

This will cause that error:

Code: Select all

if WinExist(%MyTitle%)
These are correct:

Code: Select all

ifWinExist %MyTitle%  ; Command mode, like batch files.
if WinExist(MyTitle)  ; Expression mode, like C/C++.
Refer to http://ahkscript.org/docs/FAQ.htm#percent

if WinExist(%MyTitle%) will not work even if MyTitle contains something like "Calculator" - it does not do what you think. You might liken it to dereferencing a pointer in C, but instead of a pointer, MyTitle contains a variable name. Percent signs in expressions are used for double-dereferencing.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Hugh Jars, peter_ahk, Pianist and 357 guests