NI TestStand

Showing results for 
Search instead for 
Did you mean: 

How to use Evaluate with NewSubProperty

Go to solution



I am trying to use Evaluate with NewSubProperty, but I am getting an error message



More Details:


1- A step - in runtime - will create a container in 'StationGlobals.TM_Parameters_In_Global'. The name of container is defined in runtime.





2- The next step will create a new field in the above created container.


#NoValidation(Evaluate("RunState.Main.StationGlobals.TM_Parameters_In_Global." + Parameters.TMname + ".NewSubProperty(" + Locals.ExtractedTM_ParameterValues[Locals.LoopIndex].ParameterName + ",PropValType_Number,False," + Locals.EmptyString + ",PropOption_DoNothingIfExists)")) 



and I am getting the following error message:


Severity	Rule	Category	Text	File	Location	Justification to Ignore
Error	Expressions must evaluate to a value of the expected type	General	Error in argument 1, 'Evaluate("RunState.Main.StationGlobals.TM_Parameters_In_Global." + Parameters.TMname + ".NewSubProperty(" + Locals.ExtractedTM_ParameterValues[Locals.LoopIndex].ParameterName + "\,PropValType_Number\,False\," + Locals.EmptyString + "\,PropOption_DoNothing, in call to the expression function '#NoValidation'.
Error in call to expression function 'Evaluate'.
Unexpected token: \	TM_GetGlobalParam_Rev2.0.0.0.seq	Seq["CreateUniqueParameters"].Main["Create_TM_container"].TS.PostExpr	<None>



3- by the way, the following code works without problem (by hard coding the container name in 'StationGlobals.TM_Parameters_In_Global')


#NoValidation(Evaluate("RunState.Main.StationGlobals.TM_Parameters_In_Global.TM_FPU_HF_Prepare_OpenLoop.NewSubProperty(" +  Locals.ExtractedTM_ParameterValues[Locals.LoopIndex].ParameterName + ",PropValType_Number,False, \"\",PropOption_DoNothingIfExists)"))



any advice how can I fix the code mentioned in step 2?

0 Kudos
Message 1 of 8



I would set a breakpoint and cut the code into pieces, and test the parts in runtime in the watch expression pane.

Like test the following:


Evaluate("RunState.Main.StationGlobals.TM_Parameters_In_Global." + Parameters.TMname + ".NewSubProperty(" + Locals.ExtractedTM_ParameterValues[Locals.LoopIndex].ParameterName + ",PropValType_Number,False," + Locals.EmptyString + ",PropOption_DoNothingIfExists)")

If this is also causing error, then smaller parts.

I'm sure you will find the error. 


0 Kudos
Message 2 of 8

The expressions in 'expression watch' seems to be fine. but still an exception is generated




I attached the sequence file for reference.

0 Kudos
Message 3 of 8

The question is what would you like to achieve?

I don't really get why you want to use Evaluate function


0 Kudos
Message 4 of 8

1- I want to create a container dynamically in run time (container name comes -in run time- from database)

2- I want to create fields in the above created container dynamically in run time (field name also comes -in run time- from database)

0 Kudos
Message 5 of 8

When I'm creating variables in runtime I create in Locals, not StationGlobals.

I don't use Evaluate, only create with NewSubProperty, like the following:


PropertyExists("Locals.NewVar") ? "" : RunState.ThisContext.Locals.NewSubProperty("NewVar",PropValType_Number,True,"",0)


In case of creating subproperty to a property, you have to specify the property object right, so you can create new property in that one.




0 Kudos
Message 6 of 8
Accepted by topic author hbs_80

Thanks to NI support, here is the solution (just in case someone else faced the same issue):


The method NewSubProperty expect the 'lookupString' as string: Reference link


PropertyObject.NewSubProperty ( lookupString, ValueType, asArray, typeNameParam, options) 


therefore, it is needed to add additional \" around the 'lookupString' as shown below:


RunState.Main.AsPropertyObject.Evaluate("StationGlobals.TM_Parameters_In_Global." + Parameters.TMname + ".NewSubProperty(\"" + Locals.ExtractedTM_ParameterValues[Locals.LoopIndex].ParameterName + "\", PropValType_Number, False, \"\", PropOption_DoNothingIfExists)")



0 Kudos
Message 7 of 8

Thank you, was very helpful for me. Because your example is very complex, here a more simple one:


It deletes the half of the Variable array "NoLoadCurrentIO".

Locals.ActualReportArrayName="NoLoadCurrentI0" //This variable is used very often, not only here

Locals.TempString = "Locals.Report."+Locals.ActualReportArrayName,
Locals.TempNum = GetNumElements(Evaluate(Locals.TempString)),
Locals.TempString = "Locals.Report."+Locals.ActualReportArrayName,
RunState.Main.AsPropertyObject.Evaluate(Locals.TempString+ ".DeleteElements(Locals.TempNum/2,Locals.TempNum/2)")
0 Kudos
Message 8 of 8