LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a function

The reason you can't put that function as a sub vi is because it never ends...

 

What are you trying to accomplish? 

0 Kudos
Message 11 of 14
(876 Views)

Haoyue.China wrote:

You are good at that?  I have some intrest in  that.


It is not clear what you are referring to. Please do not hijack a thread to try to talk about something else. If you need to ask a specific question, please start a new thread. 

0 Kudos
Message 12 of 14
(873 Views)

arrowminds wrote:

I know how to make a sub-VI but I cant make sub-VI including while loop.


Why not? What's the issue?

 


Infact I am making an application which involves alot of code and I am trying to make the application small by using functions or  subvi.


That does not make it small. That makes it more manageable and easier to debug and support. 

 


So can anyone guide me how to make a function containing loops (for loop or while).


It's not clear what you are asking here. Are you asking how to use loops? If so, this is covered in the tutorials. Did you go through these.

 

 

As has been asked before, what is it, exactly, that you are trying to do? It makes it difficult to help if we don't know what you want (as it should be evident by now).

 

0 Kudos
Message 13 of 14
(871 Views)

The problem is not creating a function, it's what you're trying to let the function do. 

 

The c++ function you wrote there, would have the exact same problem as the Labview code. It's just not right, there's no way to exit the loop. If your compiler doesn't choke on this, your program will. it will just print the output of a+b until something kills the code. if you have a=1 and b=2, it will print 3333333333333333333333333 and so forth.

 

 Also, you do the same calculation twice, which is a waste of cpu time. you'd better use c instead or get rid of c entirely since it's not used now. Also, you should initialize c outside of the loop to further increase performance if you do decide to use it. 

 

//possibility one: keep c, quit after n times. 

int function(int a, int b, int n);

{

int c;

for (int i=0; i<n; ++i)

  {

  c=a+b;

  cout << c << endl;

  }

return n; 

}

 

//possibility two: quit after n times, get rid of c

int function(int a, int b, int n);

{

for (int i=0; i<n; ++i)

  {

   cout << (a+b) << endl;

  }

return n; 

}

 

Keep in mind, it's been a while since I programmed c++, and I don't have a compiler on this computer so there might be an error somewhere. Good luck!

0 Kudos
Message 14 of 14
(849 Views)