I tried this and it did not work. I thought I would ask here to see if there was a way to do this..
Lets say we have some variables:
Var vr1
Var vr2
Var vr3
Now I wish to access variable "$vr1" like this:
StrCpy $0 "1"
IntOp $vr$1 $vr$1 + 1
(should be the same as "IntOp $vr1 $vr1 + 1" )
Is there a way to achieve this?
Thanks
Lane
Dynamic NSIS variables?
13 posts
I don't think what you want is possible the way you have shown it.
If you want to do this during compiletime, use macros.
e.g.,
What exactly are you trying to do with these "dynamic" variables?
If you want to do this during compiletime, use macros.
e.g.,
At runtime, you can probably use a Function
!macro INCREMENT VAR
IntOp ${VAR} ${VAR} + 1
!macroend
Section
!insertmacro INCREMENT $vr1
SectionEnd
However, I am not sure if this is what you are looking for.
Function increment
Exch $0
IntOp $0 $0 + 1
Exch $0
FunctionEnd
Section
Push $vr1
Call increment
Pop $vr1
SectionEnd
What exactly are you trying to do with these "dynamic" variables?
If you're trying to do an array of data, you can try my NSISArray plugin.
-Stu
-Stu
I should have explained better.
What I am trying to do, is to read 16 different values from an INI file (State and Text) and place each one into a matching named NSIS variable. I have this working, but it would be really nice if I could just put it into a "loop". Would make the scipt easier to read and more maintainable.
😁
To put this into a program loop, I need to be able to use what I was calling "dynamic" NSIS variables.
Can you suggest a method to do this?
Thanks
Lane
What I am trying to do, is to read 16 different values from an INI file (State and Text) and place each one into a matching named NSIS variable. I have this working, but it would be really nice if I could just put it into a "loop". Would make the scipt easier to read and more maintainable.
😁
To put this into a program loop, I need to be able to use what I was calling "dynamic" NSIS variables.
Can you suggest a method to do this?
Thanks
Lane
StrCpy $0 "1"
IntOp $vr$1 $vr$1 + 1
Shouldn't $0 actually be $1? You're setting the integer 1 to the variable $0.
But in the next line, when you're trying to run an integer operation on it, you're trying to run it on $vr$1, and you never set anything to $1.
Maybe I'm missing something here, but I don't see where else $0 comes into play.
IntOp $vr$1 $vr$1 + 1
Shouldn't $0 actually be $1? You're setting the integer 1 to the variable $0.
But in the next line, when you're trying to run an integer operation on it, you're trying to run it on $vr$1, and you never set anything to $1.
Maybe I'm missing something here, but I don't see where else $0 comes into play.
Yes, that was a "typo" on my part..
It should have been $vr$0
It should have been $vr$0
Okay, well in that case, I think you are using the IntOp operation on the wrong variable. You are using it on $vr$1, expecting it to increment the variable vr1 to become vr2. That won't happen, because it can not add an integer "1" to a string "vr1".
You should run IntOp on $0.
IntOp $0 $0 + 1
This way, the initial value "1", on the next loop becomes 2, and therefore the new variable that $vr$0 would access is "vr2".
At least I think that's what should be happening.
You should run IntOp on $0.
IntOp $0 $0 + 1
This way, the initial value "1", on the next loop becomes 2, and therefore the new variable that $vr$0 would access is "vr2".
At least I think that's what should be happening.
The best suggestion is probably Afrow UK's NSISArray plugin.
Yes, that is what I initially thought too.
But it seems the substituting "$vr$0" for "$vr1", does not work. (where $0 was set to "1").
It works in normal string substitution, but not when you need it to refer to an NSIS variable.
That is what I have been trying to get going...
Lane
But it seems the substituting "$vr$0" for "$vr1", does not work. (where $0 was set to "1").
It works in normal string substitution, but not when you need it to refer to an NSIS variable.
That is what I have been trying to get going...
Lane
That's because the substitution is being done at compiletime, not runtime.
At compile time, the compiler extracts a token named $vr$0 from the command.
It then tries to resolve the token and sees that it consists of two variables: $vr and $0.
When it tries to resolve $vr it fails.
At compile time, the compiler extracts a token named $vr$0 from the command.
It then tries to resolve the token and sees that it consists of two variables: $vr and $0.
When it tries to resolve $vr it fails.
Yes, I understand what is happenig now.
Perhaps a future NSIS release could support something like this, or could have native array support!
Thanks
Lane
Perhaps a future NSIS release could support something like this, or could have native array support!
Thanks
Lane
I think that that would just add to the installer overhead.
Edit: If you want to clean up your code, use a macro and insert it multiple times.
-Stu
Edit: If you want to clean up your code, use a macro and insert it multiple times.
-Stu
Upgrade to NSIS 2.11 and use the !tempfile, !appendfile, and !delfile commands to dynamically generate script files.
-dandaman32
-dandaman32