Page 1 of 1

error in if

Posted: 24 Apr 2024, 11:56
by cimerio
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
} 

Re: error in if

Posted: 24 Apr 2024, 12:03
by mikeyww
It's the following.

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

Explained: :arrow: Variables

Re: error in if

Posted: 25 Apr 2024, 12:55
by cimerio
the selected attachment doesn't exist anymore

Re: error in if

Posted: 25 Apr 2024, 13:37
by mikeyww
It looks like the forum has automatically provided a link to the image instead of an attachment. I have no idea why.

Re: error in if

Posted: 26 Apr 2024, 08:13
by cimerio
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
}  

Re: error in if

Posted: 26 Apr 2024, 08:36
by mikeyww
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