Archive: Labels with vars


Labels with vars
Hi, everybody!

I'm beginner in NSIS, so don't know: may be my problem isn't serious )

In NSIS we can use labels, for exapmle:

Goto label1
label1:
MessageBox MB_OK "Hello"

But, when I try to use label in such way:

StrCpy $0 "label1"
Goto $0
label1:
MessageBox MB_OK "Hello"

It didn't work. I mean I can't use var as label, or maybe I'm mistaken.
How else can I solve my problem?
Thanks for help.


Labels are defined at compile time, not runtime. (StrCpy is a runtime function).

Your example didn't make much sense becuase if the jump worked like you want, you'd end up moving forward in your script exactly as would happen without the goto line. So I'm at a loss of what it is you are trying to 'solve'.

Perhpas you could explain better what you need/want to happen?


From Goto documentation:
"If a user variable is specified, jumps to absolute address (generally you will want to get this value from a function like GetLabelAddress)"

Goto here is expecting an absolute address (like -1 or +3) and not a string label. See the manual section on GetLabelAddress and see if that can retrieve the info you need.


2 Comperio:
Ok... It was just not good example. I mean that I want to miss some steps of my program in case of my var $0
Lets say that I have several labels.
label1:
MessageBox MB_OK "Hello"

label2:
MessageBox MB_OK "Hello2"

label3:
MessageBox MB_OK "Hello3"

And when (after some operations) I need to go to label2, missing label1. If I could know it before, I would write "goto label2", but I find out about it (which label I must use) dynamically during program.


to dienjd:

I have already tried to use GetLabelAddress, but this function also doesn't "understand" string vars as argument (


StrCmp $0 "label1" label1
StrCmp $0 "label2" label2
...

Ideally you should use integer values for $0 instead of string values though.

-Stu