How to compare two variables using If Else in NSIS?

不羁岁月 提交于 2019-12-01 22:06:14

问题


Var first
Var second
Section
   Strcpy $first "1.0"
   Strcpy $Second "2.1"
   ${If} $second > $first
     MessageBox MB_OK "Grater"
   ${Else}
     MessageBox MB_OK "Smaller"
   ${EndIf}
SectionEnd

I have written the above code but it is showing me result as smaller. And how to compare a integer or double value coming from a text file with a predefined double or integer value?


回答1:


Using LogicLib, You may compare two integers like this:

Var first
Var second
Section
   StrCpy $first 1
   StrCpy $Second 2
   ${If} $second > $first
     MessageBox MB_OK "Grater"
   ${Else}
     MessageBox MB_OK "Smaller"
   ${EndIf}
SectionEnd

with capital C in StrCpy. Also try removing quotes (") from numbers to make them integers.

Another way would be this:

Push $first
Push $Second
StrCpy $first 8
StrCpy $Second 2

IntCmp $first $Second Equal Val1Less Val1More

Equal:
    DetailPrint "$first = $Second"
    Goto End
Val1Less:
    DetailPrint "$first < $Second"
    Goto End
Val1More:
    DetailPrint "$first > $Second"
    Goto End
End:

Pop $Second
Pop $first



回答2:


NSIS does not support floating point numbers in the basic instructions, you need to use the Math plugin that is part of the default install...



来源:https://stackoverflow.com/questions/35222500/how-to-compare-two-variables-using-if-else-in-nsis

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