Hi! I wrote a hotkey script based on mouseclicks for myself and coworkers which works great, but one coworker has a new monitor with a higher resolution and it requires me to change the position of one of the clicks. I wanna make my script detect the screen width and if it's 1920, do one thing, if it's another do another thing. I can't seem to get it to work. When I try the code below I get the message "Width is 1920 and it wasn't equal". What's wrong with my variable or if statement? Any help would be greatly appreciated. Here's my sample code
;Testing
^g::
Var1 :=%A_ScreenWidth%
IfEqual,Var1 ,1920
{
msgbox Congrats! Resolution matches
}else{
msgbox Width is %A_ScreenWidth% and it wasn't equal
}
return
Trouble getting variable to work
-
- Posts: 4
- Joined: 15 Aug 2018, 10:58
Re: Trouble getting variable to work
problem is ure double-dereferencing A_ScreenWidth when you do percent signs within the context of an expression ..... := %....%. this means it looks for a variable named 1920 (which is undeclared, and hence blank) and tries to fetch its value
u can fix this by replacing the expression assignment with a traditional/legacy assignment:
but id recommend just learning expression syntax instead:
u can fix this by replacing the expression assignment with a traditional/legacy assignment:
Code: Select all
Var1 = %A_ScreenWidth%
IfEqual,Var1 ,1920
msgbox Congrats! Resolution matches
else
msgbox Width is %A_ScreenWidth% and it wasn't equal
Code: Select all
if (A_ScreenWidth == 1920)
msgbox Congrats! Resolution matches
else
msgbox Width is %A_ScreenWidth% and it wasn't equal
-
- Posts: 4
- Joined: 15 Aug 2018, 10:58
Re: Trouble getting variable to work
Perfect! Thank you so much!!!!
Who is online
Users browsing this forum: No registered users and 161 guests