error in if

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
cimerio
Posts: 47
Joined: 29 Apr 2019, 15:37

error in if

24 Apr 2024, 11:56

I just can't understand why the code below shows error in line 13

Code: Select all

#SingleInstance force
SetKeyDelay, 4		
#Include arquivoDados.ahk

Esc::ExitApp

#IfWinActive ahk_class Chrome_WidgetWin_1
{
!a::
if (%CurrentMonth% = "abr" or %CurrentMonth% = "jun" or %CurrentMonth% = "set" or %CurrentMonth% = "nov") 
	%qtdias% = "30"
else
	%qtdias% = "31"
MsgBox, %qtdias%

return
} 
Last edited by gregster on 24 Apr 2024, 12:00, edited 1 time in total.
Reason: Moved from 'Scripts and Functions (v2)' to v1 help since this is v1 and a help request, and not a working v2 script or function.
User avatar
mikeyww
Posts: 27140
Joined: 09 Sep 2014, 18:38

Re: error in if

24 Apr 2024, 12:03

It's the following.

AutoHotkeyU64240424-1301-001.png
Why the code shows an error message
(94.66 KiB) Downloaded 23 times

Explained: :arrow: Variables
cimerio
Posts: 47
Joined: 29 Apr 2019, 15:37

Re: error in if

25 Apr 2024, 12:55

the selected attachment doesn't exist anymore
User avatar
mikeyww
Posts: 27140
Joined: 09 Sep 2014, 18:38

Re: error in if

25 Apr 2024, 13:37

It looks like the forum has automatically provided a link to the image instead of an attachment. I have no idea why.
cimerio
Posts: 47
Joined: 29 Apr 2019, 15:37

Re: error in if

26 Apr 2024, 08:13

mikey, I changed to code below and the error disappearead. but now the result is wrong. always show '31', but the current month is apr. should be '30'

Code: Select all

#SingleInstance force
SetKeyDelay, 4		
#Include arquivoDados.ahk

Esc::ExitApp

#IfWinActive ahk_class SciTEWindow
{
!a::
if (%CurrentMonth% = "abr" or %CurrentMonth% = "jun" or %CurrentMonth% = "set" or %CurrentMonth% = "nov") 
	qtdias := 30
else
	qtdias := 31
MsgBox, %qtdias%
MsgBox, %CurrentMonth% 

return
}  
User avatar
mikeyww
Posts: 27140
Joined: 09 Sep 2014, 18:38

Re: error in if

26 Apr 2024, 08:36

I recommend reading about expressions and If in the documentation. Ideas are below. This shows how to refer to expressions. In most situations, % is not used to refer to variables in expressions.
Variable names in an expression are not enclosed in percent signs (except for pseudo-arrays and other double references). Consequently, literal strings must be enclosed in double quotes to distinguish them from variables.
Source: Variables and Expressions - Definition & Usage | AutoHotkey v1

Code: Select all

#Requires AutoHotkey v1.1.33.11
a := 1
If (a = 1)
 b := 3
MsgBox % b

Code: Select all

#Requires AutoHotkey v1.1.33.11
qtdias := 31
If (A_MMM ~= "i)abr|apr|jun|set|sep|nov")
 qtdias := 30
MsgBox 64, Result, % qtdias

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: AlFlo, Aqualest and 102 guests