LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Simple Variable increment question

This is probably the simplest thing to do but i cannot figure it out using labview.Using line by line coding its so easy.
 
I want to assign a variable with initial value x=0. Then increment that variable value everytime a case statement is true and
diplay the value to the screen.Therefore x now becomes x=x+1.Dead easy...can some one show me a screen picture how this is done ?
 
If i create a local variable i cannot wire it as an output to anything which is confusing me.
 
Labtech5555
0 Kudos
Message 1 of 13
(15,696 Views)
You need to take the time to read the Getting Started Manual.  You need to invest tme to save time.  Here is you starter program.  Total time = 1 minute
Matt Fitzsimons
NI Alliance Member
LabVIEW Champion
NI Certified LabVIEW Architect
LabVIEW, LV-RT, Vision, DAQ, Motion, and FPGA
0 Kudos
Message 2 of 13
(15,691 Views)
The code
Matt Fitzsimons
NI Alliance Member
LabVIEW Champion
NI Certified LabVIEW Architect
LabVIEW, LV-RT, Vision, DAQ, Motion, and FPGA
Message 3 of 13
(15,690 Views)

Lets do it without a local variable. Instead of the case statement, you could also use an event structure.

 



Message Edited by Dennis Knutson on 03-15-2008 08:29 AM
Message 4 of 13
(15,688 Views)

Hi Guys,

Thanks for your help,first Matt.Sorry i am currently at home using a very old version of Labview so cannot open your file.

A picture of the screen might be better or version 8.0 which i could open later...I've had a look at the help again an now see how to

change the local variable from read to write.I can get it working ok with boolean data but still gives strange results if try to use intergers

as with my initial example above.

Dennis,I understand your program and that might be a solution for what i am trying to do but would still like to understand how it

can be done with a local variable.

Labtech5555

0 Kudos
Message 5 of 13
(15,673 Views)


labtech5555 wrote:

I can get it working ok with boolean data but still gives strange results if try to use intergers
as with my initial example above.


What is your definition of "strange results"??? Please attach your code so we can tell you what the problem is.
 
If you want to modify the example by Dennis with a local variable instead of a shift register, lust delete the shift register and place a local variable(read) to the left of the case structrure where the wire enters the case. Then you need a second one in a data dependent frame outside the loop so it resets before the loop starts. A shift register is the highly preferred solution. (A shift register (or feedback node) is cleaner and more efficient, in starts at zero automatically, it does not require extra data copies in memory, it uses dataflow to minimize the possibilties of race conditions, etc.)
Message 6 of 13
(15,670 Views)

I'm not sure I want to show you how a local variable can be used. Local variables certainly have a place in LabVIEW programming but they are usually the most abused feature. They violate every rule of data flow, cause race conditions, create unnecessary copies of data, and often are just lazy programming. You really need to have a good justification for using a local instead of a wire.

If you are getting strange results, then you should post your code.

Message 7 of 13
(15,669 Views)

Hi Guys,

I am used to line by line C programming which of course uses variables to control things.Changing to labview

is totally differant thinking as event driven, but i'm still thinking about variables which are nomally easy to control and declare in C programming..

If i seen an example what i wanted originally then i may agree its the wrong way to go and use what Dennis has suggested.

I can't try it untill i go back to work on Monday on the project i' writing...

The example i tried to today is in version 6 so to old to post and i've deleted it already anyway..Instead of getting x incrementing by by 1 at

a time it was going up by a very large number everytime the case was triggered.If no success i'll right it again at work and post on Monday ..

Thanks,

              Labtech5555

0 Kudos
Message 8 of 13
(15,660 Views)

If the variable was incrementing constantly, then you probably have the mechanical action of the boolean to one of the switch modes. Set it instead to Latch (i.e. Latch When Released). Here's an event structure with a local. The while loop and case statement in my earlier post can be use as well.

You'll need to shift your thinking a bit when you move to LabVIEW. I went throug the same learning curve when I moved from text based languages to LabVIEW. There are some excellent resources for Learning LabVIEW at http://www.ni.com/academic/lv_training/how_learn_lv.htm.

 



Message Edited by Dennis Knutson on 03-15-2008 11:36 AM
Message 9 of 13
(15,655 Views)


labtech5555 wrote:

The example i tried to today is in version 6 so to old to post and i've deleted it already anyway..
Instead of getting x incrementing by by 1 at a time it was going up by a very large number everytime the case was triggered


This means two things that are probably easy to correct:
  1. Your loop does not have a wait statement. (every polling UI loop needs a wait (the earlier eample by Dennis above has a 250ms wait, limiting the loop time to 4/second).
  2. Your button is NOT set to latch action. (it is probably set to "switch when pressed" (like a door bell) or "switch until relased") This means that if you press it, it will stay TRUE for a long time, and since the loop spins at a speed only limiited by the CPU (millions of iterations/second!) the increment executes many times in a row. If you set the button to latch action, it will only be true exactly once per press and will reset to false as soon as the code has a change to read the new value. To change the mechnical action, right-click on the button and select "mechanical action...latch when released".



Message Edited by altenbach on 03-15-2008 10:39 AM
Message 10 of 13
(15,651 Views)