Archive: Variable is not resolved


Variable is not resolved
Hi, I require to assign text conditionally to a variable. Unfortunately the variable $versionLabel is not resolved, it always remains "$versionLabel" instead of printing out its value.

Any help is greatly appreciated.
----------------------------------------------------------
!define MINOR_VERSION "e"

!include "MUI.nsh"
!include "LogicLib.nsh"

Name "PROFIDA Update"
Var "versionLabel"

Section "-vardef"
${If} ${MINOR_VERSION} != ""
StrCpy "$versionLabel" " [${MINOR_VERSION}]"
${EndIf}

DetailPrint "this is $versionLabel > sould equal ${MINOR_VERSION}"
SectionEnd

!define VERSION '${MAJOR_VERSION}$versionLabel ${UPDATE_COUNT}'
...


not able to reproduce the problem

OutFile 'test.exe'

!include "LogicLib.nsh"
!define MINOR_VERSION "e"
Var "versionLabel"

Section "boo"
StrCmp ${MINOR_VERSION} "" end
StrCpy "$versionLabel" " [${MINOR_VERSION}]"
DetailPrint "this is $versionLabel > sould equal ${MINOR_VERSION}"

${If} ${MINOR_VERSION} != ""
StrCpy "$versionLabel" " [${MINOR_VERSION}]"
${EndIf}

DetailPrint "this is $versionLabel > sould equal ${MINOR_VERSION}"

end:
SectionEnd

daniel8, OutFile is a compile time command. You can't use variables in it. Those will only be set during runtime. Imagine you used the computer name in that variable. How is the compiler to know on which computer you'll run the installer and give it the matching name?


Thanks for taking time to work on my problem.

kichik, all variables like ${VERSION_FILE} are resolved properly anywhere in my file except $versionLabel. Even when using DetailPrint $versionLabel remains "$versionLabel" instead of filling in its value. I tried the same using $0, $1, $R1 but the result is always the same.

I am using NSIS version 2.23

Red Wine, are you using maybe a different version of NSIS?


I'm using 2.23, the little example I posted above should work for all 2.0 + versions, does not work for you? Still the var $versionLabel is empty?


${VERSION_FILE} is not a variable, it's a compile time define.

If you tried to DetailPrint it and it printed the variable name itself, you probably had a typo in there. Pay attention to the warnings the compiler gives you. It'll tell you if it doesn't know a specific variable in this case.


kichik, I do not get any error nor any warnings.

Red Wine and kichik, please have a look at the compiler output below - $versionLabel remains $versionLabel and is not resolved to the value it actually holds. I used Red Wine's snippet from above.
---------------------------------------------------------
Processing script file: "D:\Documents\Development\Updates\TestUpdate\variableTest.nsi"
OutFile: "test.exe"
!include: "C:\programs\dev\NSIS\Include\LogicLib.nsh"
!include: closed: "C:\programs\dev\NSIS\Include\LogicLib.nsh"
!define: "MINOR_VERSION"="e"
Var: "versionLabel"
Section: "boo"
StrCmp "e" "" equal=end, nonequal=
StrCpy $versionLabel " [e]" () ()
DetailPrint: "this is $versionLabel > sould equal e"
!insertmacro: _If
!insertmacro: end of _If
StrCpy $versionLabel " [e]" () ()
!insertmacro: _EndIf
!insertmacro: end of _EndIf
DetailPrint: "this is $versionLabel > sould equal e"
SectionEnd


Once again, you are confused with the difference between compile time and runtime. The compiler can't tell what $versionLabel will hold when the installer is executed so it prints out the variable name itself. When you actually execute the installer, the variable name will be replaced by its runtime value.


kichik and Red Wine, thanks for all the patience and help - you put me onto the right track, it works via use of !ifdef and !define.

I searched this forum for the keywords "compile time variable" and also understand now the purpose of the section "Conditional Compilation" in the NSIS user manual.