Click to See Complete Forum and Search --> : Incrementing variable name NOT the value of the variable itself.


jaynefly
10-21-2003, 01:47 AM
I need a way to generate a variable name that is incremented as the code goes through a loop. I am not looking for a way to increment the value of the variable. Rather, I need to increment the variable name. ie: var1, var2, var3....

I am using a database query on the server, this stores the information in an array.

I need to run a loop within a loop. And I would like to be able to increment the variable name in the following way....


for (var i = 0; i<"#1stQuery.recordcount#"; i++) {

var varname[i] = new WebFXTreeItem( query1_results[i] );
tree.add(varname[i]);

for (var j = 0; j<"#2ndQuery.recordcount#"; j++) {

var varname[j] = new WebFXTreeItem( query2_results[j] );
varname[i].add(varname[j]);
}

}


Any help would be great.

Thanks,
Jayne

Gollum
10-21-2003, 02:02 AM
Have you considered using arrays?


var aWebFX = new Array;
var aWebFXItems = new Array;
for (var i = 0; i<"#1stQuery.recordcount#"; i++)
{
aWebFX[i] = new WebFXTreeItem( query1_results[i] );
tree.add(aWebFX[i]);

aWebFXItems[i] = new Array;
for (var j = 0; j<"#2ndQuery.recordcount#"; j++)
{
aWebFXItems[i][j] = new WebFXTreeItem( query2_results[j] );
aWebFX[i].add(aWebFXItems[i][j]);
}
}