04-18-2022 04:22 PM - edited 04-18-2022 04:23 PM
I have inherited some code that now has to accepts arguments from the command line, so that it changes behavior depending on the arguments. The problem is that the VI that actually needs to change behavior is run in a subpanel via the "Insert VI" method, and is compiled into the executable. A Static Reference is used to obtain the reference to the VI, and then the VI is inserted into a subpanel on the front panel of the main VI (please see attached illustration). It's easy to get the command-line arguments (the User Input string), but how do I pass those to the VI that is invoked via Insert VI?
04-18-2022 04:35 PM
"Insert VI" doesn't actually run the VI, it just sticks it in the panel.
Either:
If you just need to run it "normally" then all you need to do is call the subVI itself in the usual way you would call it.
If that's not the case, then you probably need to do something more complicated, such as a "call by reference" node.
04-18-2022 04:38 PM
04-18-2022 04:38 PM
You need to provide significantly more detail because your description is too ambiguous and the image makes no sense at all.
Can you attach a simplified example?
There are plenty of ways to change certain values in a VI, why does it have to be command-line arguments?
04-18-2022 05:14 PM
Yes, that's correct, further in the code that same VI Ref (obtained from the Static VI Ref) is used in an Invoke Node with Run VI method. But I can't see how that helps.
Ultimately the user arguments have to affect the behavior of the VI that's run, but the user arguments are only available to the main VI. The only thing that the main VI passes on to Insert VI is the VI reference, and that same reference is passed onto Run VI (see attached). All that is very clever and works smoothly.
04-18-2022 05:26 PM
Hi altenbach, it doesn't have to be command line arguments, but to me it's the simplest way. I need to know who is running the program, and depending on that, modify the appearance/behaviour of the VI that runs in the subpanel. The list of users can be stored, e.g. into a .ini file.
Main VI knows that user John is using it (by, say, supplying "John" as command line argument), it looks up user John's parameters in the .ini file, and tells the VI in the subpanel to act accordingly. At least that's my initial approach.
04-18-2022 05:41 PM
So the set control value by name method should work.
04-18-2022 06:05 PM
Thanks, JÞB, I'll look into it.
04-19-2022 03:00 PM
Many thanks to all who suggested solutions. I wanted to wrap this up as I found a way to make it work. I used a Functional Global Variable that stores the relevant cluster with parameters when the main VI starts, and then the VI that runs in the subpanel just reads those from the FGV and customizes the FP according to the parameters for that user.
04-20-2022 10:11 AM
@gmand wrote:
Many thanks to all who suggested solutions. I wanted to wrap this up as I found a way to make it work. I used a Functional Global Variable that stores the relevant cluster with parameters when the main VI starts, and then the VI that runs in the subpanel just reads those from the FGV and customizes the FP according to the parameters for that user.
That sounds like a lot of trouble to pass parameters.
Why not run the VI as a normal subVI, and pass the subpanel reference too. Then, make the VI put itself in the subpanel.
This eliminates VI server completely. A big advantage...