LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Simple Counter

Hi Everyone,

 

I wanted to create a simple counter with a Start Button and a Stop Button. Here is my VI currently and I'm somewhat stuck. I read that you don't want to create a while loop inside an event structure. I was wondering what is another way for me to implement this simple counter with a Start and Stop button.

 

Thanks for your help

B

0 Kudos
Message 1 of 9
(21,493 Views)

I have modified your vi to what i understood:

-I have never seen someone telling using whiles loop inside event structure.

-Below code whenever you click on Increment it increments by 1.

-Remaining time it'll be waiting for an event to happen here either Stop or increment events.

counter.png

Thanks
uday
0 Kudos
Message 2 of 9
(21,475 Views)

Based on your VI, you are missing even the most basic principles in LV. I would suggest to take some available tutorials. Also, do not start with Event structure at the beginning, first you should understand the basics, then after how to work with Event structure.

One possible solution:

 

Counter_BD_timeout.png

 

Counter_BD.png

 

0 Kudos
Message 3 of 9
(21,469 Views)

Without comment on coding practices, to just change what you have so it works...

First, you need to put the stop inside the loop, otherwise the inside of the loop only sees the value originally passed in.

~MyBitmap.png

 

Also, you need to edit the event so it doesn't lock the panel.

~MyBitmap.bmp

0 Kudos
Message 4 of 9
(21,459 Views)

@Mancho00 wrote:

Without comment on coding practices, to just change what you have so it works...

First, you need to put the stop inside the loop, otherwise the inside of the loop only sees the value originally passed in.

 

Also, you need to edit the event so it doesn't lock the panel.

 


I do not think it is good to teach bad programming practices. Yes, this works, but an Event structure without a While loop around it is just silly. Also, changing the panel lock behaviour can be problematic in certain cases.

I really suggest the OP to take the official tutorials and teaching material to see proper programming style...

0 Kudos
Message 5 of 9
(21,439 Views)
Using shift register and an event (to increment and stop)inside loop as suggested by few others is the simple solution all you can try....

As your requirement is simple with small changes in the existing code (looping inside event structure)may work, which will make you to follow in larger application and encounters lot of issues....
So please strict to coding guidelines though it's a simple requirement
----------------------------------------------------------------------------------------------------------------
Palanivel Thiruvenkadam | பழனிவேல் திருவெங்கடம்
LabVIEW™ Champion |Certified LabVIEW™ Architect |Certified TestStand Developer

Kidlin's Law -If you can write the problem down clearly then the matter is half solved.
-----------------------------------------------------------------------------------------------------------------
0 Kudos
Message 6 of 9
(21,429 Views)

You don't need any event structure. Don't overcomplicate things!

 

 

(initialize the shift register if desired.)

Download All
Message 7 of 9
(21,421 Views)

Thanks everyone for your suggestion and help. Background for me is that I have been taking the NI Core tutorials. Just a starting out programmer so not too familiar with coding styles just yet. Not Labview savvy as everyone but I have to start somewhere. Thanks again for the help.

 

 

0 Kudos
Message 8 of 9
(21,396 Views)

@brianmnguyen wrote:

Thanks everyone for your suggestion and help. Background for me is that I have been taking the NI Core tutorials. Just a starting out programmer so not too familiar with coding styles just yet. Not Labview savvy as everyone but I have to start somewhere. Thanks again for the help.

 


https://www.ieee.li/pdf/viewgraphs/significance_of_labview_development_style.pdf

----------------------------------------------------------------------------------------------------------------
Palanivel Thiruvenkadam | பழனிவேல் திருவெங்கடம்
LabVIEW™ Champion |Certified LabVIEW™ Architect |Certified TestStand Developer

Kidlin's Law -If you can write the problem down clearly then the matter is half solved.
-----------------------------------------------------------------------------------------------------------------
0 Kudos
Message 9 of 9
(21,373 Views)