LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Creating a progress bar

Hi,

 

I try to use a progress bar in a bigger code.

It should also stop if the user stops the code.

 

I attached a the code I created. The only difference here is that the while loop cancels the other loop. Thats not the case in the bigger code, there the while loop just listens. I think the code works correctly, but can you help me where it code be coded in a better way? It looks really messy for me.

 

greetings

melody

 

edit: somehow i can not get the timing correctly

0 Kudos
Message 1 of 11
(2,414 Views)

It's not bad at all.

 

You can make it better though by simply straightening some wires, making sure they are not going from right to left:

Before:

wiebeCARYA_0-1646321801116.png

 

After:

wiebeCARYA_2-1646321727918.png

 

 

The error coming out of obtain notifier doesn't really do anything. If there is an error obtaining the notifier, the reference is invalid and the Waits will throw an error anyways.

0 Kudos
Message 2 of 11
(2,405 Views)

wiebe@CARYA wrote:

It's not bad at all.

 

You can make it better though by simply straightening some wires, making sure they are not going from right to left:

Before:

wiebeCARYA_0-1646321801116.png

 

After:

wiebeCARYA_2-1646321727918.png

 

 

The error coming out of obtain notifier doesn't really do anything. If there is an error obtaining the notifier, the reference is invalid and the Waits will throw an error anyways.


I agree that it stands quite well on its own.  The main thing is that you can tell that a lot of thought was put into making it readable.  It's mostly about personal preferences here.

 

FYI, code neatness isn't just about being anal; it is essential, especially when creating complicated code.  (It really shouldn't be too complex, but that's a discussion for another time.)  The reason for this is essentially the same as the reasons for using regular indents in text coding: It doesn't matter to the compiler that you have random indents, but if someone came looking for you because he wanted to strangle you for using random indents, I'd point to your desk and go to lunch so I could have some plausible deniability.  Keep the wires as straight as you can, don't have them running behind stuff, don't have objects hiding behind others, stuff like that, and it will be easy to read, easy to maintain, and easy to troubleshoot.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 3 of 11
(2,397 Views)

Why. So. Complicated???

 

  • A FOR loop with a termination condition will stop after all iterations have completed, so the lower comparison is pointless.
  • You do calculations on all integer DBL constants to create an integer. Maybe there is an all-blue solution. It also belongs before the loop (even though the compiler will treat it as loop invariant code anyway).
  • Not sure what the point of the lower loops is.  A 1s wait and a 1ms timeout seems contradictory. I don't think you need that loop at all (but I defer judgement until I see the bigger code).
  • You don't really need to wire the high resolution seconds across the loop. You really also don't need to take a reading with each iteration if all you are interested in is the last value.
  • Shouldn't "meldung" have a different mechanical action?

Maybe all you need is the following (It even updates the elapsed time with each iteration):

 

altenbach_0-1646325431934.png

 

 

0 Kudos
Message 4 of 11
(2,375 Views)

I would also suggest to make the progress bar invariant to N so it goes to 100% over all outer iterations no matter what's wired to N. One possibility:

 

altenbach_0-1646327649135.png

 

0 Kudos
Message 5 of 11
(2,361 Views)

@altenbach wrote:

I would also suggest to make the progress bar invariant to N so it goes to 100% over all outer iterations no matter what's wired to N. One possibility:


I just use a Property Node to set the Scale->Range->Maximum to be N-1.  I can then just wire the FOR Loop's iteration terminal directly to the indicator.



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
Message 6 of 11
(2,347 Views)

@crossrulz wrote:

@altenbach wrote:

I would also suggest to make the progress bar invariant to N so it goes to 100% over all outer iterations no matter what's wired to N. One possibility:


I just use a Property Node to set the Scale->Range->Maximum to be N-1.  I can then just wire the FOR Loop's iteration terminal directly to the indicator.

 


In most cases, I show the digital display too, so this won't work 😄

 

altenbach_0-1646331975884.png

 

0 Kudos
Message 7 of 11
(2,337 Views)

thanks for your replies, I will go through them today.

 

The first version was just a for loop. But when I had testruns over a few days (like 30) the progressbar would update every 30 days/100 and in that case the stop button lost its purpose. That is why I did create an inner loop to get more updates of the status of the stop button

0 Kudos
Message 8 of 11
(2,315 Views)

As I said, you could just place the stop button inside the inner loop. In a pinch, even a local variable might work.

 

If your problem are in different code, maybe you should show us that. It is possible that you have some dataflow problems. How longs is one iteration?

0 Kudos
Message 9 of 11
(2,311 Views)

One iteration depends on the time I run the program. I had N as 100 maximum in the for loop.

 

Until know I haven't used property nodes. But that solution works perfect ... took me some time to find our that I have to change it to accept input parameters 😄

0 Kudos
Message 10 of 11
(2,266 Views)