From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

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
(19,407 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
(19,389 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
(19,383 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
(19,373 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
(19,353 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
(19,343 Views)

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

 

 

(initialize the shift register if desired.)

Download All
Message 7 of 9
(19,335 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
(19,310 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
(19,287 Views)