evaluating concatenated variables

Post Reply
melanie
Posts: 6
Joined: Sat Jul 08, 2000 3:15 pm

evaluating concatenated variables

Post by melanie »

hiya,
Is there a way to concatenate (and then evaluate) 2 variables to create a reference to another variable - Like eval('my' + 'var') to get the value of the variable called "myvar" in javascript?

This small, "made up" code snippet below may give you an idea of what i'm looking to do . . .

<a name="myFormFunction">
<form action="postForm.html" method="post">
. . .

<input name="val1" value="$'val1'"><br>
<input name="val2" value="$'val2'"><br>
<input name="val3" value="$'val3'"><br>

. . .
</form>
</a>

<a name="postForm">
<!--
(READ val+$i as evaluated variable that I'm trying to make)
-->
<$i = 0>
<$max = 10>
<while $i lt $max>
<sql max=1 novars "insert into mytable values(counter, val+$i)"></sql>
<$i = (1+$i)>
</while>
</a>

Mucho Thanks,
Mel
melanie
Posts: 6
Joined: Sat Jul 08, 2000 3:15 pm

evaluating concatenated variables

Post by melanie »

Hmm . . . I think I've got it . . .but is there a more elegant solution that I'm missing (excluding arrays)?

<$i = 0>
<$MEL0="melanie">
<$MEL1="mel">
<$MEL2="melba toast">
<while $i lt 3>
<strfmt "$$MEL%s" $i>
<strfmt "insert into testtable values(counter,%s)" $ret>
<$x = $ret>
<sql max=1 novars $ret></sql>
<$i=(1+$i)>
</while>
User avatar
John
Site Admin
Posts: 2622
Joined: Mon Apr 24, 2000 3:18 pm
Location: Cleveland, OH
Contact:

evaluating concatenated variables

Post by John »

You can use <getvar> as to get the value of a named variable. This will only work if the variable is a CGI variable, or named elsewhere in the script, e.g.

<$MEL0="melanie">
<$MEL1="mel">
<$MEL2="melba toast">
<while $loop lt 3>
<strfmt "MEL%s" $loop>
<getvar $ret>
<sql max=1 novars "insert into testtable values(counter, $ret)"></sql>
</while>
John Turnbull
Thunderstone Software
Post Reply