If Expressions Don't Work

谁说我不能喝 提交于 2019-12-25 07:43:15

问题


I'm having a problem with getting if expressions to work. The problem is that the first if statement is used, even if the expression beside should return a value of FALSE.

For example, when I run this script, it should be that %X% would have a value of 10 by the time it has run twice. (First is 5, second is 10). %length% would then incidentally have a value of 2 on the second run.

The message box that I get on the second run says "The length of InputVar is 2. - One - 2" all the way up through the 19th run which says "The length of InputVar is 2. - One - 19". Then when it hits runs 20 (through 22), it says "The length of InputVar is 3. - One - 20".

What am I doing wrong?

^1::
X:=0
Y:=0
Loop, 22
{
Y:=++Y
X:=5+X
InputVar:=X
StringLen, length, InputVar
if (%length%<2)
{
MsgBox, 1, Length, The length of InputVar is %length%. - One - %Y%, 2
}
else if (%length%==2)
{
MsgBox, 1, Length, The length of InputVar is %length%. - Two - %Y%, 2
}
else if (%length%>2)
{
MsgBox, 1, Length, The length of InputVar is %length%. - Three - %Y%, 2
}
else
{
MsgBox, 1, Length, The length of InputVar is %length%. - Unknown - %Y%, 2
}
Sleep 500
}
Return

;These are the written numbers I should expect to be paired up with %Y%.
;One - 1
;Two - 2-19
;Three - 20-22

回答1:


I edited the original post. Check the first line.

(Solved! I needed to get rid of the % in %length% when comparing it against the value of 2.)

Edit: And, BGM, did you know you have to wait a day to mark your own answer as the correct answer? I won't be back tomorrow :)



来源:https://stackoverflow.com/questions/18177057/if-expressions-dont-work

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!