Why this string compare doesn't work Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
AHKStudent
Posts: 891
Joined: 05 May 2018, 12:23

Why this string compare doesn't work

08 Aug 2020, 11:55

Code: Select all

var := "today-xyz"
test := strsplit(var, "-").2 
;msgbox, % test
if (test != "xyz") || (test != "fff")
{
	MsgBox, xyz ; why is this msgbox showing if it does = xyz
}
else
{
msgbox, ignore
}

ExitApp
gregster
Posts: 4961
Joined: 30 Sep 2013, 06:48

Re: Why this string compare doesn't work  Topic is solved

08 Aug 2020, 12:02

why is this msgbox showing if it does = xyz
You are using or (||) - so (test != "fff") will evaluate to true, if var is xyz, because it's not fff.
Because you use or, that's enough to make the whole expression true.
AHKStudent
Posts: 891
Joined: 05 May 2018, 12:23

Re: Why this string compare doesn't work

08 Aug 2020, 12:28

gregster wrote:
08 Aug 2020, 12:02
why is this msgbox showing if it does = xyz
You are using or (||) - so (test != "fff") will evaluate to true, if var is xyz, because it's not fff.
Because you use or, that's enough to make the whole expression true.
thanks I changed it to &&

Return to “Ask For Help”

Who is online

Users browsing this forum: A_AhkUser, FanaticGuru, pelos, w0z, XShayanX and 49 guests