Variable Variables

Fuzzmaster

New Member
Does WebSpeed support variable variables?

In PHP if:

$var = 'Account';
$Account_001 = 'Some Account';
$Account_002 = 'Another Account';
$CurrentAccount = $var.'_001';

Then:

$$CurrentAccount = 'Some Account';

This is handy for lots of reasons... I know given the example an array would be better; however, this is simply and example. I typically use variable variables to populate my form objects while maintaining a little more flexibility than arrays offer.

Or:

Am I just being dense?
 
Hi Fuzzmaster,

Have you tried to use the 'set-user-field' and 'get-user-field' functions? These are probably not exactly what you are after, but they may just do the job for you :) The usagle is pretty obvious: set-user-field("myField":U,"This is the value") and to retrieve the value again: myVariable = get-user-field("myField":U). In that, "myField" can be replaced with a variable...

Paul
 
Thanks Paul, I will certainly play with that Idea.

My use of "populate" may have been misleading. Here's a better example of what I typically use variable variables for in PHP and the solution I came up with for WebSpeed...

In PHP:

<?php $str = 'ObjectName'; $STR = 'usr_'.$str; ?>
<TH>
<LABEL FOR="<?= $str ?>"><?= $str ?></LABEL></TH><TD>
<INPUT ID="<?= $str ?>" NAME="<?= $str ?>" TYPE="text" VALUE =<?= isset($$STR) ? $$STR : NULL ?>" />
</TD>
<?php unset($str); unset($STR); ?>

In WSS:

<!--WSS ASSIGN str = 'ObjectName'. -->
<TH CLASS="right">
<LABEL FOR="`str`">`str`</LABEL></TH><TD>
<INPUT ID="`str`" NAME="`str`" TYPE="text" VALUE="`get-value(str)`" />
</TD>
<!--WSS ASSIGN str = ''. -->

Being a lazy coder, I hate to rewrite code, so I use variable variables to both create and populate (on POST/GET) many of my html elements. I use (cut/paste/inc) these "templates" instead of simple arrays so I still have the flexibility to style or modify (CSS/SIZE/MAXLENGTH) each element.

I was trying too hard it seems; since I'm not converting the POST into variables (as I do with PHP) I can get away with dropping nulls without causing serious grief in the way of undeclared variables.

As I delve deeper, perhaps I'll find a better way.
 
Back
Top