Archive: How to define user variables and use "if" commands


How to define user variables and use "if" commands
I am searching for a way to define a user variable and assign a value.
Then, later, I want to access this variable value again in an "if" construction.
I want to avoid asking the user multiple times the same question.

It should work similar to:

MessageBox IDYESNO "Do you want to install version A?" IDNO no
$myvariable="A"
InstallDir "C:\project\versA"
Goto next
no:
$myvariable="B"
InstallDir "C:\project\versB"
next:
...
Section "blah1"
...
if ($myvariable == "A")
File /oname=karl.txt C:\projectA\bin\karl.txt
else
File /oname=karl.txt C:\projectB\bin\karl.txt
....
SectionEnd

Section "blah2"
...
if ($myvariable == "A")
File /oname=paul.txt C:\projectA\bin\paul.txt
else
File /oname=paul.txt C:\projectB\bin\paul.txt
....
SectionEnd

Section "blah3"
...
if ($myvariable == "A")
File /oname=peter.txt C:\projectA\bin\peter.txt
else
File /oname=peter.txt C:\projectB\bin\peter.txt
....
SectionEnd


Defining user specific variables is not possible yet. You can always use one of the twenty variables that are built in ($0-$9, $R0-$R9), they are usually enough. If you are coming short on variables you should probably start arranging your script with Push and Pop to avoid overriding previous values. For example:

Push $0 # old value of $0 saved on stack
StrCpy $0 "something"
# more stuff with $0
Pop $0 # old value of $0 returned from stack to $0


If you can't solve the shortage with this trick then you can always write the data into an INI file or the registry and delete it when the installation finishes.

For the if you should use StrCmp and IntCmp. Example:

StrCmp $0 "bla" eq diff
eq:
MessageBox MB_OK "$$0 = bla"
Goto done
diff:
MessageBox MB_OK "$$0 != bla"
done: