Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Problem with if and multiple conditions


  • Please log in to reply
7 replies to this topic
Puzzled Greatly
  • Members
  • 612 posts
  • Last active: May 22 2017 11:15 PM
  • Joined: 15 Aug 2009
If I try this code:

test1 = recent
test2 = .

if test1 = recent && test2 = .
msgbox OK
else
msgbox error!
I get the error! message rather than OK.

If I try this code:

test1 = recent
test2 = .

if (test1 = recent && test2 = .)
{
msgbox OK
}
else
{
msgbox error!
}
Then I get a system error saying "The following variable name contains an illegal character: "."

I tried escaping the . with `. but still got the illegal character message. How can I get this to work?

Thanks,

GP

MasterFocus
  • Moderators
  • 4323 posts
  • Last active: Jan 28 2016 01:38 AM
  • Joined: 08 Apr 2009
test1 = recent
test2 = .
; OR
; test1 := "recent"
; test2 := "."

If ( test1 = "recent" && test2 = "." )
; OR
; If ( test1 = "recent" ) && ( test2 = "." )
  MsgBox, ok
Else
  MsgBox, not ok

Read carefully: <!-- m -->http://www.autohotke...s/Variables.htm<!-- m -->

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Antonio Fran├ža -- git.io -- github.com -- ahk4.net -- sites.google.com -- ahkscript.org

Member of the AHK community since 08/Apr/2009. Moderator since mid-2012.


jaco0646
  • Moderators
  • 3165 posts
  • Last active: Apr 01 2014 01:46 AM
  • Joined: 07 Oct 2006
Have a look at my recent post in the Tutorial for Newbies thread.

Puzzled Greatly
  • Members
  • 612 posts
  • Last active: May 22 2017 11:15 PM
  • Joined: 15 Aug 2009
Thanks for the replies. I missed the need for using quotation marks. I find working out when they are needed a little bit confusing. I actually got this to work without quotation marks:

test1 = recent
test2 = .

if test1 = recent
{
	if test2 = .
		msgbox OK
}
else
msgbox error!


joshebosh
  • Members
  • 2 posts
  • Last active: Feb 08 2019 04:33 AM
  • Joined: 17 Jun 2013
Can someone help me with this multiple condition issue?
I've tried several combos, different things, but dont know whats going wrong
 
I'm trying to set three different window placements, but only two are working.
 
only the first and last are working of the conditions,
the middle condition    "else if (%manyCam1% = 1)"
is not working even though the first condition reports the variable is indeed set to one.
I dont know what i'm doing wrong.
 
;#########################################################
; MANYCAM WINDOW ALIGNMENT
;#########################################################
 
manyCam = 0
 

^!+m::
IfWinExist, ManyCam Options
{
	if (%manyCam% = 0)
	{
		WinMove, 1925, 342
		manyCam = 1
		MsgBox manyCam variable is now %manyCam%
		Return
	} else if (%manyCam% = 1) {
		WinMove, -1918, 29
		manyCam = 2
		MsgBox manyCam variable is now %manyCam%       
		Return
	} else {
		WinMove, 2979, 28
		manyCam = 0
		MsgBox manyCam variable is now %manyCam%
		Return 
	}
}
Return


sinkfaze
  • Moderators
  • 6367 posts
  • Last active: Nov 30 2018 08:50 PM
  • Joined: 18 Mar 2008
In expression mode variables do not require percent signs unless you are "double-dereferencing":
 
if (manyCam = 0)


AfterLemon
  • Moderators
  • 237 posts
  • Connoisseur of Boobs
  • Last active: Jan 04 2016 11:12 PM
  • Joined: 09 Oct 2012
For the sake of non-confusion, "Double-Dereferencing" can be understood as such:
REFERENCE:
A := "B"
MsgBox, % A
Variable "A" contains string "B"
---

DOUBLE-REFERENCE
A := "B"
%A% := "C"
MsgBox, % B
Variable "A" contains string "B"
Variable "B" is referenced with a Dereference(%A%) and now contains string "C"
---

DOUBLE-DEREFERENCE
Now, if we then call Variable "A" in a Double-Dereferenced method, we will get string "C"
A := "B"
B := "C"
MsgBox, % %A%
---

EXPRESSION MODE DOUBLE-DEREFERENCE
Within an expression, the portion after the Open Parens "(" and before the Equal "=" is a Variable.
Thus:
A := "B"
B := "C"
If (%A% = "C")
   MsgBox, % %A%


joshebosh
  • Members
  • 2 posts
  • Last active: Feb 08 2019 04:33 AM
  • Joined: 17 Jun 2013
Thank you sinkfaze for the answer to my problem.

Thank you AfterLemon for the explanation.

First I've heard of double-dereferencing.
20 years on a computer = noob :-)