Archive: If Else


If Else
Hello everyone.

I'm using InstallOptions to gather a parameter from the user and can't quite figure out how to execute an if/else structure. I'm asking the user whether they are using Com1, Com2, or USB and I want to set an INI file parameter to 1, 2, or 5 depending on the response. How might one do this? Thanks for the help.

-Justin


Example:

ReadIniStr $R0 "yourfile.ini" "Field 1" "State"

StrCmp $R0 "1" 0 +3
;COM1
WriteIniStr "anotherfile.ini" "Use Port" "COM1"
Goto done

ReadIniStr $R0 "yourfile.ini" "Field 2" "State"

StrCmp $R0 "1" 0 +3
;USB
WriteIniStr "anotherfile.ini" "Use Port" "USB"
Goto done

done:

The +3 works as a relative jump, ignoring spaces between commands and ignoring comments.

So,

StrCmp $R0 "1" 0 +3

If $R0 is 1 then goto 0 (carry on)
Else (if $R0 is anything else but 1,) then skip the next 2 commands onto the 3rd command.

-Stu


It goes to the third command after the jump, so it skips two, not three.


LOL yes

-Stu


Thanks! Worked like a charm!
-Justin