|
Vittorio Beginner
Joined: 22 Oct 2003 Posts: 10
|
Posted: Fri Jan 23, 2004 8:28 am
stringlist question |
I have a stringlist variable named @testvar containing several values (say, "1|2|3|4|5"). I tried to set one of the values using the following notation..
testvar.2=1
Not only does that not work, the "index" values of the list get all screwed up. The previous list is wiped out, and a zero value at zero (??) index remains. If you try to add more values to the same variable.. the list now starts at index zero instead of one.
What is going on? Is there a shorthand way to do what I want? |
|
|
|
Danlo Magician
Joined: 28 Nov 2003 Posts: 313 Location: Australia
|
Posted: Fri Jan 23, 2004 9:39 am |
%replaceitem is the function you are looking for. I can't remember what syntax it uses and I seem to have misplaced my help files somewhere.
#var testvar {%replaceitem(NewValue,@testvar,2)}
I think it is. |
|
|
|
megamog75 Enchanter
Joined: 20 Nov 2002 Posts: 627 Location: USA
|
Posted: Fri Jan 23, 2004 4:51 pm |
When researching your above exampl
testvar.2=1 this is what I found
say your variable had 4 items in it the structure would be
1 through 4 with item one being the first item
but when you use var.1=1 you give the variable a numbered structure starting with the first number "0"
and because you changed the variable structure you reset the variable
Now this is a good way to do your varables you just have to remember to use the follow procedures:
to place the first item you would do this...
test.1=1
will set the First item in the variable to 1
the first variable is #show %item(@test,0)
or #show test.0
get it?
then the Second item would be:
test.2=50
to show it
#show test.1 will show the second item which in this case is 50 |
|
|
|
megamog75 Enchanter
Joined: 20 Nov 2002 Posts: 627 Location: USA
|
Posted: Fri Jan 23, 2004 4:53 pm |
also after you first change the structure it will reset the varable to null but then you can make any changes you want with out messing it up.
so test.1=30
would change the second item from 50 to 30
#show test.1 would show you 30 |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Fri Jan 23, 2004 5:39 pm |
testvar.2=1 creates an array variable. You cannot use this notation for assigning list values.
Sorry, but you'll have to use %replaceitem. For your example, to assign a value of 1 to the second item in the @testvar list, any of these will work:
#VAR testvar %replaceitem( 1, 2, @testvar)
testvar = %replaceitem( 1, 2, @testvar)
forpeoplewhohatespaces=1;testvar=%replaceitem(@forpeoplewhohatespaces,2,@testvar) |
|
|
|
|
|