LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to resuse the code

Hi there,

  I would like to have your opinion on code reuse. We have a pretty big system and have so many code (vi's and subvi's) developed years ago. Many subvi's will be used and embedeed into a new program on and on. For example, I need subviA, subviB and subviC embedded in a new code. For some cases, I expect some subvi's are unchangable once embedded into the new project while in other case, I expect some subvi might be changed in future. I will give you some example, if I have a subvi used to sort some data, I called it quick_sort, the way to implement quick_sort doesn't really matter, so it is changable. If I start several projects each of them have a quick_sort embedded, it is possible to have modify the quick_sort in future. But in other case, I might have some subvi once embedded into the project, it will never changed even someone modify the source code of those subvi's. Now in our code, one subvi might be referred by so many vi's, if I accidently modify that subvi, it is possible that many subvis will be affected. So is that any way to reuse some code (subvi's) by code copy instead of code reference?

0 Kudos
Message 1 of 6
(2,518 Views)

Copying code to reuse it is not really the way to go.  I've done that  quite a bit and it becomes a nightmare to keep straight (project A ends up pointing to VIs over in project B and visa versa).  The best way to reuse code it to have in in your palettes.  And the best way to do that is with VI Package Manager.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 6
(2,512 Views)

@crossrulz wrote:

Copying code to reuse it is not really the way to go.  I've done that  quite a bit and it becomes a nightmare to keep straight (project A ends up pointing to VIs over in project B and visa versa).  The best way to reuse code it to have in in your palettes.  And the best way to do that is with VI Package Manager.


So you mean using VI Package Manager could reuse the code without cross reference? I don't know how but what I want is says, I have a vi (inside there is a lot subvi's used). I would like to use all codes but keep all the code in local folder not as globally accessible (i.e. not cross reference).

 

I am switch to labview 2012 from labview 7, I saw that in 2012, one could create a project, vi, polymorphic VI and somehting like class. I am wondering what's the difference to start a project and develope vi inside and simply develope the VI without the project? I try both but can tell the difference.

 

Also, I have some expereience in object-oriented programming in C++ but is that anything related to OOP to write a class in labview? Any advantage to use class in labview? I read several books but I didn't see any one use class programming.

0 Kudos
Message 3 of 6
(2,508 Views)

Say you have subvi a,b,c,d

Why cant you create one folder for one project have all the VIs and subVI in same folder.According to you subvi a,b,c,d and other is part of it.


Each time new project you want to create then copy the same folder which created for previous project hence
all the subvi will be copied. then change subvi a,b,c(d is not used) according to new project.

 

This allows you to change subvi according to current project and it wont affect you subVI outside.

 

Hope this is useful.

 

Thanks.

--------------------------------------------------------------------------------------------------------
Kudos are always welcome if you got solution to some extent.

I need my difficulties because they are necessary to enjoy my success.
--Ranjeet
0 Kudos
Message 4 of 6
(2,478 Views)

Thanks. That's the way I did in my labview 2012. But in my lab, we only have labview 7 and to start a new code, usually we needed more than 100 subvi (some projects used even more). And some subvi will call other subvi .... so to figure out what subvi must be copied is really a headache; also, in labview 2012, I check that if you copy a, b, c, d to a new folder to start a new code, then the code will refer to the local a, b, c, d, but it seems not the case in labview 7, it also refer to the old one before being copied.


@Ranjeet_Singh wrote:

Say you have subvi a,b,c,d

Why cant you create one folder for one project have all the VIs and subVI in same folder.According to you subvi a,b,c,d and other is part of it.


Each time new project you want to create then copy the same folder which created for previous project hence
all the subvi will be copied. then change subvi a,b,c(d is not used) according to new project.

 

This allows you to change subvi according to current project and it wont affect you subVI outside.

 

Hope this is useful.

 

Thanks.


 

0 Kudos
Message 5 of 6
(2,451 Views)

It's quite easy to extract which code is needed. Create a Code distribution with the root vi. 😉

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 6 of 6
(2,433 Views)