LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

select only even



krispiekream wrote:
sorry about the local variables i tried not to, but i cant help it.
i didnt know how to initialize current position to 0 since it labview remember the last position it was at.

That's why the indicator is to the right of the shift register and not inside the event structure. It will update right away! No local needed.
Of course 0 might not be a TRUE index, so you might want to search for the first TRUE before the loop and initialize the shift register accordingly

krispiekream wrote:
how about i want to let the user select the element?
0,1,2,3,6,7,9

and current position always start at 0.
click advance to go to 1,
click advance again to go to 3
click advance again to go to 6
click advance again to go to 7
click advance again to go to 9

Why should it skip over 2?
IF you also want 2, my code will do exactly that! Have you tried?


Message Edited by altenbach on 05-07-2008 09:30 AM
Message 31 of 47
(1,622 Views)
i have this code,
its what i wanted..but i dont know how to get rid of the local variables?
my while loop is not ending right..
by the way..thanks for the help...

Best regards,
Krispiekream
0 Kudos
Message 32 of 47
(1,609 Views)
this code is more correct, but the search that you have, gets stuck from position 6 to position 7.
i have to click advance three times because it index was at 3 when it last found position 6.
advance click 1 to index 4,
advance click 2 to index 5
advance click 3 to index 6.
 
Best regards,
Krispiekream
0 Kudos
Message 33 of 47
(1,597 Views)
try this:
 
(it spins the loop once via timeout to find the first location).
 
(btw: You are still NOT incrementing from the found position. Compare with my code!)
 
 


Message Edited by altenbach on 05-07-2008 09:54 AM
Message 34 of 47
(1,587 Views)


krispiekream wrote:
yeah. i am modifiying a program have are filled with sequences and stacked quences with 10 frames or so.
its hard for me to clean it up because i am still learning labview and i all these stacked sequences i look at everyday got me used to the style.

Already 10 frames...  and growing 😞
 
Do whoever will look at your code in the future a favor.  Please remove the stacked sequences.  It is not something good to get used to. 😞
 
It will be harder and harder to add features, functionality to the code and to maintain it in the future.  It's a good time for you to learn a better coding style.  Let me guess...  Is there any comment within any one of those 10 frames?  -- sorry to sound so strict, but we always get called to fix someone's messy stacked structures...  😞
0 Kudos
Message 35 of 47
(1,578 Views)
wow, thats nice..
and correct..
last question..
i want to change current position to be a control, so that
i can type in...

when i am at position 2. i dont want to click adv to 6, then to 8, then to 9.

from 2, i want to skip 6,8 and go straight to 9..

Best regards,
Krispiekream
0 Kudos
Message 36 of 47
(1,578 Views)
------------------------------------------------------------------------
Already 10 frames...  and growing
 
Do whoever will look at your code in the future a favor.  Please remove the stacked sequences.  It is not something good to get used to.
 
It will be harder and harder to add features, functionality to the code and to maintain it in the future.  It's a good time for you to learn a better coding style.  Let me guess...  Is there any comment within any one of those 10 frames?  -- sorry to sound so strict, but we always get called to fix someone's messy stacked structures... 

---------------------------------------------------------------------------


yeah, there are comments on the messy stacked structures...
but i cant follow it is i lose track after the first two frames.
i hate stacked structures too, but i am so used to seeing them in our codes. i want to clean it up, but i dont know how to start and it can take months for me. co-worker say, "if it is not broken, why fix it"


Best regards,
Krispiekream
0 Kudos
Message 37 of 47
(1,573 Views)


krispiekream wrote:
"if it is not broken, why fix it"


          
0 Kudos
Message 38 of 47
(1,553 Views)
Try to think of it in this way: If you cannot follow it after two frames, then it is already broken. Not broken in the sense that the code will not execute, but broken in the sense that you cannot understand what it is doing in order to fix or modify its behavior.

No one ever has the time to do it over - Until it is so broken that it cannot be fixed and the boss or the customer needs it working yesterday. Then they hire consultants like some of the people who are trying to help you here.

Or as someone once described a similar situation (somewhat sarcastically): "We never have time to do it right the first time, but we can always find time to do it over again."

Lynn
Message 39 of 47
(1,549 Views)


krispiekream wrote:
------------------------------------------------------------------------


yeah, there are comments on the messy stacked structures...
but i cant follow it is i lose track after the first two frames.
i hate stacked structures too, but i am so used to seeing them in our codes. i want to clean it up, but i dont know how to start and it can take months for me. co-worker say, "if it is not broken, why fix it"



If you get ambitious and want to clean it up , here is what you do.
 
Right click on the stacked sequence and select replace with flat sequence.  This will make the screen real estate really blow up and to the right.
Go through the frames and shrink the code down.  (you may even want to do this before the first step and try to make the over all stacked sequence structure as small as possible so it doesn't blow up as much to begin with.)
Your sequence locals will now show up as tunnels between frames.  Look for sequential frames that don't need to be in separate frames.  Right click the border between and select merge frames.
Shrink down the frames more as needed trying to eliminate extra white space.
If you have local variables, look for the first occurrence in the first frame where the value is started, don't write anything back to itself, just look to merge a local write with a following local read by deleting the locals and wiring them together.
If you have a local read at the beginning of the entire sequence and a local write at the end, look at a shift register to carry the value back into the next iteration.
When you are done, you should have very few locals left.  Try to use the terminal for the control or indicator for one of them (such as right before the loop ends)
 
This can be really messy because the diagram gets large and many frames may have a lot of white space, but within 10-15 minutes you can do a lot to shrink it all up, let it be just a flat sequence with maybe a couple of frames if necessary (and you can probably eliminate the entire sequence structure.)  If you have large chunks of code that take up a lot of space with only a couple of inputs and outputs (and especially if these functions are repeated), then turn those chunks into subVI's.
 
I myself would rather have a flat sequence (if necessary) that goes 3 screens wide rather than a 3 frame stacked sequence that all fits into 1 screen.  (Worst is numerous frames and embedded stacks that stretch across multiple screens.)
Message 40 of 47
(1,546 Views)