Source language: Translate to:

Set a variable variable

Questions or information that don't quite fit anywhere else

Moderator: Neosoft Support

Set a variable variable

Postby HPW » Wed Sep 25, 2013 11:15 pm

I run across the problem to set a variable variable.
It is logical but I did not get it first. ;-)

A sample code from a loop:
Code: Select all
  ...
  SetVar "[NewVarArt]" "[Variable[vCounter]]"
  SetVar "[[NewVarArt]]" "[VarValue]"
  ...


You have to use the double brackets.

Regards
Hans-Peter
User avatar
HPW
 
Posts: 2510
Joined: Fri Apr 01, 2005 11:24 pm
Location: Germany

Re: Set a variable variable

Postby Neosoft Support » Thu Sep 26, 2013 11:28 am

I think it works doesn't it?
NeoSoft Support
Neosoft Support
NeoSoft Team
 
Posts: 5593
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA

Re: Set a variable variable

Postby dpayer » Fri Sep 27, 2013 7:00 am

Neosoft Support wrote:I think it works doesn't it?


What Hans-Peter shows does work for me:
Code: Select all
SetVar "[NewVarArt]" "[Variable[vCounter]]"
  SetVar "[[NewVarArt]]" "[VarValue]"


But I did find that initially I had some issues when I had not given the 'naming' variable ( HPW's example: [NewVarArt] ) a value prior to using it. IOW my coding was poorly structured.

I notice in NB that if a variable is set to be empty
Code: Select all
setvar "[test]" ""


the variable is considered non-existent and does not appear in the debugger. This can be confusing if you are attempting to determine if a variable has a value or not. I would think it would show in the debugger in the variable section with an identifier that it is empty.

But, if I DEFINE the variable with a global attribute,
Code: Select all
DefineVar "[test]" "String" "" "Global" ""

it does display in the debugger. With a local attribute, it displays when it is called but then is gone from the debugger afterward.
David Payer
Des Moines, Iowa
USA
User avatar
dpayer
 
Posts: 1380
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Re: Set a variable variable

Postby HPW » Fri Sep 27, 2013 7:06 am

It did work, I only wants to show that it can be used this way.
Hans-Peter
User avatar
HPW
 
Posts: 2510
Joined: Fri Apr 01, 2005 11:24 pm
Location: Germany

Re: Set a variable variable

Postby Neosoft Support » Fri Sep 27, 2013 11:04 am

I notice in NB that if a variable is set to be empty

setvar "[test]" ""

the variable is considered non-existent and does not appear in the debugger. This can be confusing if you are attempting to determine if a variable has a value or not. I would think it would show in the debugger in the variable section with an identifier that it is empty.


We could have gone either way, but as it is setting a variable to a null value "" removes the variable from memory. Without the debugger window you wouldn't even realize this fact, because NeoBook treats non-existent and empty variables exactly the same. The downside to showing empty variables is the need to keep them in memory somewhere. The DefineVar action was introduced in part to provide the ability to declare typed variables in advance. Declared variables stick around even when they are set to a null value. This was an evolution of NeoBook over time that is no doubt confusing to new users since it's not really necessary except in specific situations.
NeoSoft Support
Neosoft Support
NeoSoft Team
 
Posts: 5593
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA


Return to Misc. Questions and Information

Who is online

Users browsing this forum: No registered users and 1 guest