BookmarkSubscribe
Choose Language Hide Translation Bar
David_Morrow
Community Trekker

Populate a table using table variables

I am trying to populate a table using the table variables. ( sample table attached)

The first 3 columns of the table are created from the table variable name and the 4th column is the table variable value

 

row 1   : target[0].target__reflectance_pc = 3  :Ambient_level W/m2 = 0    :zone_id_r =1  :Result = 400

row 2   : target[0].target__reflectance_pc = 3  :Ambient_level W/m2 = 0    :zone_id_r =2  :Result = 400 

row 3   : target[0].target__reflectance_pc = 3  :Ambient_level W/m2 = 10  :zone_id_r =1  :Result = 100

row 4   : target[0].target__reflectance_pc = 3  :Ambient_level W/m2 = 10  :zone_id_r =2  :Result = 100

 

And so on for all the table variables in the table

Any help with this would be much appreciated.  

 

 

 

 

 

 

 

0 Kudos
1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Populate a table using table variables

The below script will populate your data table with values from the Table Variables.  I have also attached a new version of your Test data table.  The one you had attached had a formula in one of the columns, which did not permit the table to populate.

Names Default To Here( 1 );
dt = Current Data Table();

tableVarNamesList = dt << get table variable names;

For( i = 1, i <= N Items( tableVarNamesList ), i++,
	dt << add rows( 1 );
	Column( dt, "target[0].target__reflectance_pc" )[i] =
	Num( Word( 2, tableVarNamesList[i], "," ) );
	Column( dt, "Ambient_level W/m2" )[i] =
	Num( Word( 3, tableVarNamesList[i], "," ) );
	Column( dt, "zone_id_r" )[i] = Num(
		Word( 4, tableVarNamesList[i], ",)" )
	);
	Column( dt, "result" )[i] = Num(
		dt << get table variable( tableVarNamesList[i] )
	);
);
Jim

View solution in original post

0 Kudos
2 REPLIES 2
txnelson
Super User

Re: Populate a table using table variables

The below script will populate your data table with values from the Table Variables.  I have also attached a new version of your Test data table.  The one you had attached had a formula in one of the columns, which did not permit the table to populate.

Names Default To Here( 1 );
dt = Current Data Table();

tableVarNamesList = dt << get table variable names;

For( i = 1, i <= N Items( tableVarNamesList ), i++,
	dt << add rows( 1 );
	Column( dt, "target[0].target__reflectance_pc" )[i] =
	Num( Word( 2, tableVarNamesList[i], "," ) );
	Column( dt, "Ambient_level W/m2" )[i] =
	Num( Word( 3, tableVarNamesList[i], "," ) );
	Column( dt, "zone_id_r" )[i] = Num(
		Word( 4, tableVarNamesList[i], ",)" )
	);
	Column( dt, "result" )[i] = Num(
		dt << get table variable( tableVarNamesList[i] )
	);
);
Jim

View solution in original post

0 Kudos
David_Morrow
Community Trekker

Re: Populate a table using table variables

Thank you that is exactly what I was trying to do.

0 Kudos