Cancel
Showing results for 
Search instead for 
Did you mean: 

Excel Dynamic Object and Variable Imports and changes

Solution Partner Pioneer Solution Partner Pioneer
Solution Partner Pioneer

Hi guys,

 

At the moment I have an excel (attached below).

 

I have different machines (object column), but for every machine there can be different vaaribles (Obj_Var) I want to change.

 

I would like to run a script that can dymically pick up which variable I am working with and do something as follows:

 

(I know this is not how it works: just as an example)

 

for var i:=1 to Table.YDim

    Table["Object",i] +"."+Table["Obj_Var",i] := Table["Value",i]

next

 

The problem is that I will need to change variables very quickly (on site at the client with the excell) and therefore I do not want to hardcode. 

 

Thank You in advance.

 

4 REPLIES

Re: Excel Dynamic Object and Variable Imports and changes

Valued Contributor
Valued Contributor

I think you are quite close. Try and see if this works:

 

(If the "Object"-column and "Obj_Var"-column are of type string)

 

for var i:=1 to Table.YDim

   str_to_obj( Table["Object",i] +"."+Table["Obj_Var",i] ) := Table["Value",i]

next

 

-----------------------------------------------------------------------------------------------------------------

(If the "Object"-column and "Obj_Var"-column are of type object)

 

for var i:=1 to Table.YDim

   str_to_obj( to_str(Table["Object",i]) +"."+to_str(Table["Obj_Var",i] )) := Table["Value",i]

next

 

Re: Excel Dynamic Object and Variable Imports and changes

Solution Partner Pioneer Solution Partner Pioneer
Solution Partner Pioneer

It does not accept "Object"+"varaible" as an object.

 

The varaible can also not be stored as an object (Screeshoots attched below).

 

to me it seems as if you can only do a str_to_obj conversion with an object name (something that is completely an object). However for a variable it looks like it would need to be converted in a different way [eg: str_to_varaible > something like that]

Re: Excel Dynamic Object and Variable Imports and changes

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

try this instead

 

for var i:=1 to Table.YDim

   str_to_obj(Table["Object",i].setAttribute(Table["Obj_Var",i] , Table["Value",i])

next
Steffen Bangsow
freelance simulation specialist  
web: www.bangsow.eu
mail: steffen@bangsow.net

Re: Excel Dynamic Object and Variable Imports and changes

Solution Partner Pioneer Solution Partner Pioneer
Solution Partner Pioneer

That seems to have done the job.

 

The only part of my code that is still hardcoding is the "Values". As they are all strings I have to specify to which data type I need to convert it.

 

I attched my code below: