If inside if Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
klb1111
Posts: 9
Joined: 11 Oct 2018, 06:47

If inside if

11 Oct 2018, 07:05

Hello,

can't figure out why the second if is working (message box appears) while it shouldn't start.
It shouldn't start because second if should return false.
Could you help please?

Code: Select all

T1:
FormatTime, TimeString, T10, Time
If (TimeString >= 1400)
{
if (2>=1)
{
MsgBox The current time and date (time first) is %TimeString%.
}
}
return
Image
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: If inside if

11 Oct 2018, 07:20

The if inside returns true because you checked if 2 is larger or the same as 1.
Recommends AHK Studio
User avatar
Scr1pter
Posts: 1272
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: If inside if

11 Oct 2018, 07:32

Also, it's useful to add some tabs inside of your code.
Especially for beginners (I don't know your programming knowledge), it helps you keep the overview.
For example (just to focus on the structure) :

Code: Select all

if ...
{
  while ..
  {
    if
    {
  
    }
  }
}
return
Regards
Please use [code][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09
klb1111
Posts: 9
Joined: 11 Oct 2018, 06:47

Re: If inside if

11 Oct 2018, 09:20

nnnik wrote:The if inside returns true because you checked if 2 is larger or the same as 1.
I've messed it with "1>=2" condition, thank you.
Actually my real check is:

Code: Select all

if (WinExist ("ahk_class #32770"))
but it returns True even if such window does not exist.
Is there a way to get list of all existing windows with their ahk_class value?
klb1111
Posts: 9
Joined: 11 Oct 2018, 06:47

Re: If inside if

11 Oct 2018, 09:29

Scr1pter wrote:Also, it's useful to add some tabs inside of your code.
Especially for beginners (I don't know your programming knowledge), it helps you keep the overview.
...
That looks really convenient, thank you.
My programming knowledge is very very basic :D
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: If inside if

11 Oct 2018, 09:34

Code: Select all

if (WinExist ("ahk_class #32770"))
Is a blank var concatenated with a string literal, and not a function call as you might have intended. Delete the space.
klb1111
Posts: 9
Joined: 11 Oct 2018, 06:47

Re: If inside if

11 Oct 2018, 11:41

swagfag wrote:

Code: Select all

if (WinExist ("ahk_class #32770"))
Is a blank var concatenated with a string literal, and not a function call as you might have intended. Delete the space.
It still returns True while it shouldn't do so. Just can't figure out why.
Image
klb1111
Posts: 9
Joined: 11 Oct 2018, 06:47

Re: If inside if

11 Oct 2018, 13:21

UPD.

In this code

Code: Select all

T1:

FormatTime, TimeString, T10, Time
If (TimeString >= 1400)

{
   if WinExist ("ahk_class #32770")
   {
   MsgBox % "The active window's ID is " . WinExist("A")
   }

}

return
Second IF statement which is: if WinExist ("ahk_class #32770")
runs "MsgBox % "The active window's ID is " . WinExist("A")" string
even if there is no window with "#32770" class.

I've used NirSoft winlister to check:
Image

As you can see there's no window with such class but the result of the second IF statement is TRUE.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: If inside if  Topic is solved

11 Oct 2018, 13:27

Code: Select all

if WinExist ("ahk_class #32770")
this isnt a function call. delete the space:

Code: Select all

if WinExist("ahk_class #32770")
klb1111
Posts: 9
Joined: 11 Oct 2018, 06:47

Re: If inside if

17 Oct 2018, 13:08

swagfag wrote:
11 Oct 2018, 13:27

Code: Select all

if WinExist ("ahk_class #32770")
this isnt a function call. delete the space:

Code: Select all

if WinExist("ahk_class #32770")
Got it. Many thanks!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: filipemb, mikeyww, PsysimSV, RussF and 297 guests