11-25-2020 07:36 AM - edited 11-25-2020 08:32 AM
Hello,
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.
#NoValidation(RunState.Main.StationGlobals.TM_Parameters_In_Global.NewSubProperty(Locals.TM_Name,PropValType_Container,False,"",PropOption_DoNothingIfExists))
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?
Solved! Go to Solution.
11-26-2020 02:56 AM
HI,
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.
11-26-2020 06:42 AM - edited 11-26-2020 06:55 AM
The expressions in 'expression watch' seems to be fine. but still an exception is generated
I attached the sequence file for reference.
11-26-2020 08:13 AM
11-26-2020 08:24 AM
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)
11-27-2020 04:02 AM
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.
12-03-2020 06:35 AM
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)")
08-27-2021 11:59 AM
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)")