Archive: Comparison code


Comparison code
Hello,
in a custom page I would assign to 15 variables ($0 to $R5) 15 integers from 1 to 15. This assignments must be unique so two or more variables must have not the same value. For this I written the following not working code:


Function

!insertmacro MUI_INSTALLOPTIONS_READ $0...$R5 ; Read 15 assignments
${For} $0 1 15 ; Check every assignment by eachother
Call CheckSame
${Next}
FunctionEnd

Function CheckSame
StrCpy $R9 0 ; reset same assignment counter
${Switch} $0
${Case} $1 ;check assignment #1
IntOp $R9 $R9 + 1
${Case} $2 ;check assignment #2

IntOp $R9 $R9 + 1
${Case} $3 ;check assignment #3
IntOp $R9 $R9 + 1
${Case} $4 ;check assignment #4
IntOp $R9 $R9 + 1
${Case} $5 ;check assignment #5

IntOp $R9 $R9 + 1
${Case} $6 ;check assignment #6
IntOp $R9 $R9 + 1
${Case} $7 ;check assignment #7
IntOp $R9 $R9 + 1
${Case} $8 ;check assignment #8
IntOp $R9 $R9 + 1
${Case} $9 ;check assignment #9
IntOp $R9 $R9 + 1
${Case} $R0 ;check assignment #10
IntOp $R9 $R9 + 1
${Case} $R1 ;check assignment #11
IntOp $R9 $R9 + 1
${Case} $R2 ;check assignment #12
IntOp $R9 $R9 + 1
${Case} $R3 ;check assignment #13
IntOp $R9 $R9 + 1
${Case} $R4 ;check assignment #14
IntOp $R9 $R9 + 1
${Case} $R5 ;check assignment #15
IntOp $R9 $R9 + 1
${EndSwitch}
${If} $R9 > 1 ; if two or more assignments have same value then return to the page
Abort
${EndIf}
FunctionEnd



This code does not work because the IntOp $R9 $R9 + 1 instructions (the counter for duplicated values) are always all executed reporting always the value $R9=15 even I specify only two or three identical values (then they should be executed only two or three times giving $R9=2 or $R9=3): all the cases must be evaluated, but only for the same assignments values they must be executed (then I do not need the break statement).



Can you give me the right code for this ?


You forgot ${Break} in every ${Case}.


Also in this case it does not work; I had to use {If} logiclib to make it now work.

Regards