LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

For Loop

Can someone tell me why the "for loop" doesn't exit the first time through if I enter the correct number of characters (10)?

0 Kudos
Message 1 of 3
(915 Views)

Hi fforgit,

 


@fforgit wrote:

Can someone tell me why the "for loop" doesn't exit the first time through if I enter the correct number of characters (10)?


Because you don't "OBEY THE DATAFLOW!"

 

Why do you access the value of that string indicator using a difficult way with property nodes?

Why don't you use the wire coming out of that ExpressVI?

Why do you hide the label of the integer indicator in the block diagram?

Why do you compare "i" with "2"? In a loop set to run only twice???

 

Solution:

Read the LabVIEW help on the topic "THINK DATAFLOW!". Then use more wires…

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 3
(900 Views)

As Gerd already mentioned, the dataflow principle is totally violated here. Since the entire code is just plain silly, I really recommend to spend a few hours on LabVIEW tutorials and look at some example

 

  • Your loop will stop after two iterations max, no matter what, because that's wired to N. None of your lower comparisons are ever needed.
  •  You also need to know that LabVIEW starts counting with zero, thus i=1 at the second iteration.
  • Property nodes such as "update while typing" only need to be set if you want to change the property, not with every iteration of the loop. Thus it belongs before the loop. Of course this particular property only makes sense for string controls and is completely irrelevant for indicators as in your case. Do you know the difference between control and indicator? You cannot type into an indicator at runtime!
  • Your loop diagram has two independent code fragments: (1) The dialog and (2) the rest of the code. Both fragments will run in parallel as soon as each iteration starts. (LabVIEW does not execute left to right! Execution order is entirely determined by data dependencies). This means that the value property will get read way before you finish the dialog thus operating on a stale value. A proper data dependency to delay the rest of the code would be to wire the serial number output directly to the string size and permanently delete the property nodes and references. The serial number indicator is not even needed, especially since you have it outside the viewable area. If you actually need it, it would belong after the loop.
0 Kudos
Message 3 of 3
(883 Views)