07-17-2023 01:42 PM
I might be trying to do too much here...But I want to dynamically create the variable name in the expression box for an input parameter to a VI Call.
right now I have an embedded select statement that looks like this:
parameters.selectVariable = "one" ? FileGlobals.myContainer.one : parameters.selectVariable = "two" ? FileGlobals.myContainer.two : FileGlobals.mycontainer.three
it works. I just think it's kind of clunky. Since my selectVariable has the same name as the container I want to select, I'd like to just build the name on the expression line so it would look something like this if it's possible:
FileGlobals.myContainer.<value of parameters.selectVariable>
I got the idea from building a file name for a property file in the following manner: "filePrefix" + locals.fileSelect + "fileSuffix.xlsx"
Is this possible? Am I just making things too complicated and I should just stick with the select statement?
Thanks!
Solved! Go to Solution.
07-22-2023 02:10 PM
A couple options:
Option 1: Locals.MyContainer.GetValString(Locals.SelectedVariable, 0) That will return the value
Option 2: Evaluate("Locals.MyContainer." + Locals.SelectedVariable)
Hope this helps,
07-26-2023 12:53 PM
It absolutely helps!
Option 1 I could not get to work for me at all. I think it wants to return the value, in string format, of the Locals.MyContainer.SelectedVariable (I.e. if locals.selected variable = "number1" and locals.MyContainer.number1 = 33, then the return for this would be "33"). I had a little success using the GetDisplayNames method, but couldn't quite make it work and I don't think I really needed it anyway unless I wanted to do a compare of my Locals.SelectedVariable string variable.
Option 2 works well. I however cannot seem to make the compiler happy with this input as it keeps it glowing red and when function check is performed it says there will be a run-time error. I tried using #NoValidation() but it gives the same message with function check. I did notice that if I put a default value for Locals.SelectedVariable, and if that default matched the sub-container name, the function check returns no error. So it's evaluating that function before compile which is a little weird. If I leave SelectedVariable as blank or have an incorrect value, it shows the error. The other thing of note is that by removing the "." from "Locals.MyContainer." will also make the function check happy, but then it doesn't have a period to separate the objects and you just end up with an incorrect variable name. I tried far too long to try to solve that issue and make function check not tell me about run-time errors, but it just wouldn't do it. I tried using "Locals.MyContainer" + "." + Locals.SelectedVariable, "Locals.MyContainer" + ("." + Locals.SelectedVariable), creating a new variable that was Locals.newVar = "."+Locals.SelectedVariable then using "Locals.MyContainer" + Locals.newVar, etc.
But, at the end of the day, if you can just ignore the redness of the text in the formula box, it works just as you listed in Option 2.
Thank you for the assist!!