From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

"best practices" coding question

Solved!
Go to solution

I'm getting ready to add several command objects to my program, and the source code is going to increase correspondingly. I'd be interested in advice on good ways to break the code into multiple files.

 

I was thinking of having a source file (and a header file) for each command object. Will this cause problems when editing and saving the .uir file? When I execute the Code->Set Target File... command, it seems that it changes the target file for all objects, not just the one I'm currently working on.

 

At a minimum, I'd like to have all my callback routines in a file other than the file that contains main(). Is this a good idea/bad idea/doesn't matter? Is there anything special I need to know about doing this?

 

I guess what I'm asking is, how much liberty do I have when it comes to putting code into locations other than what the .uir editor seems to expect? Before I dive in, I want to make sure I'm not opening a can of worms here.

 

Thanks.

0 Kudos
Message 1 of 5
(3,158 Views)

You can have separate source files that correspond to different parts of your user interface by generating callbacks for a specific element instead of the entire UI. Please see this Help Topic for more information on using the Code builder to generate code for the elements of your user interface.

Regards,

Anjelica W.
National Instruments
Product Marketing Manager
FlexLogger and TestStand
0 Kudos
Message 2 of 5
(3,126 Views)

Thank you, Anjelica. Let me pose a more concrete example: If I were to add a new control button to my UI, can I tell CVI where I want to put the auto-generated code for it? It wouldn't necessarily be the same file as all the others are using. (Maybe this isn't even a good idea, but I'm trying to avoid having one enormous file with all the callbacks in it.

0 Kudos
Message 3 of 5
(3,111 Views)
Solution
Accepted by topic author mzimmers

I am not so comfortable when coming to "best practices", possibly because I am partially a self-educated programmer.

Nevertheless, some concepts are clear to me: you are not limited any way in how you split your code into separate files. I personally have the habit of grouping panels that are used for a coherent set of functions (e.g. all panels for setting tests, all panels for executing/monitoring tests...) into a single UIR file, and related callbacks into a single source file, but this is not a rigid rule.

I have some common callback functions that are in a separate source file, some of them very commonly used throughout my programs are included in my own instrument driver and installed to controls either in the UIR editor or in code.

 

When you are using the UIR editor, you can use Code >> Set target file.. menu function to set the source file where generated code will go. This option can be changed any time while developing, so ideally you could place a button on a panel, set a callback routine for it, set the target file and then generate the code for this control only (Ctrl+G or Code >> Generate >> Control Callbacks menu function). Until you change the target file, all generated code will go to the original target file, but you can move it to a different source after this moment.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 5
(3,104 Views)

Hi, Roberto -

 

The term "best practices" probably wasn't the ideal phrasing on my part. I was mainly interested in what experienced people considered "good form" when programming within the CVI paradigm. I was also not sure about controlling code destinations, but you answered that. Thanks.

0 Kudos
Message 5 of 5
(3,093 Views)