Archive: While Loop not working as expected...


While Loop not working as expected...
Hi,

I've been working with NSIS for quite some time now and rarely ran into an issue which left me totally clueless. In fact this forum and the documentation solved pretty much all questions so far.

With this one though I am out of ideas. All the variables are defined in an external NSH file which is being included, that worked like a charm so far.

My input variables are...

!define PRODUCT_TYPE "ABC"

!define DISTRIB_WEBSITES_ABC "3"

!define DISTRIB_WEBSITE1_TXT_ABC "Website Title 1"
!define DISTRIB_WEBSITE1_URL_ABC "http://www.example1.com"
!define DISTRIB_WEBSITE2_TXT_ABC "Website Title 2"
!define DISTRIB_WEBSITE2_URL_ABC "http://www.example2.com"
!define DISTRIB_WEBSITE3_TXT_ABC "Website Title 3"
!define DISTRIB_WEBSITE3_URL_ABC "http://www.example3.com"



The PRODUCT_TYPE defined varies depending on which installer I want to compile, the remaining variables are static - though the number of links varies hence the following while loop...


StrCpy $R1 "${DISTRIB_WEBSITES_${PRODUCT_TYPE}}"
${While} $R1 > 0
WriteIniStr "$SMPROGRAMS\${PRODUCT_NAME} ${PRODUCT_TYPE}\Links\${DISTRIB_WEBSITE$R1_TXT_${PRODUCT_TYPE}}.url" "InternetShortcut" "URL" "${DISTRIB_WEBSITE$R1_URL_${PRODUCT_TYPE}}"
IntOp $R1 $R1 - 1
${EndWhile}


...once I run this NSIS instead of creating the LNKs with the proper text/url comes up with literally my variable name as TXT and URL.

"${DISTRIB_WEBSITE1_TXT_ABC}.LNK" > "http://${DISTRIB_WEBSITE1_URL_ABC}"
"${DISTRIB_WEBSITE2_TXT_ABC}.LNK" > "http://${DISTRIB_WEBSITE2_URL_ABC}"
"${DISTRIB_WEBSITE3_TXT_ABC}.LNK" > "http://${DISTRIB_WEBSITE3_URL_ABC}"

Since the numbers are there I can assume that my loop works fine but why doesn't it put the proper details in as text/url? Do I have a general brain fart here and this an issue of the while loop working different between compile time and installation?

P.S.: To clarify, I am running NSIS 3.0a1 - worth testing the old versions?

You're using a variable ($R1) in a define name (${DISTRIB_WEBSITE$R1_TXT_${PRODUCT_TYPE}}).
That's not going to work.


Got an idea/hint on how to do this instead?


I think the best approach for you is using an array, filled with websites and titles.


Defines are not variables, they are symbols replaced with their value at compile time. And variables are set at runtime. So ${something_$R1} can't have a defined value and the compiler treats it as a string with a variable in it.
There was a question about the same problem recently and a solution was suggested; it may be worth implementing if you have lots of defines to process:
http://forums.winamp.com/showthread.php?t=365124

[Edit] You got the answer while I was writing mine. Sorry jpderuiter, I didn't see your posts; that's twice already. :)


Thank you aerDNA for the elaboration, using a batchfile IMO is anything but a clean approach. For the meanwhile I will to stick to hard coding those lines - thanks to both of you for the comments.


Another possibility: a txt file with the list. Extract at runtime and read lines in a loop.