Stopping a For Loop, part 2

Hello. Thank you everyone for your help, getting to this point. I asked for help to create a stop condition, while a For Loop is running. I was given many ideas and selected the one that used local variables. It works well however, if I am in the "Test in progress" state, in the first For Loop, and the "Stop" button is selected from the front panel, when it stops the Vi, it sends the value "5" to the second For Loop before going to the "End" state, which puts it to "0", then stops the Vi. What this Vi is doing is feeding 0-200VDC signal to an eddy current sensor, then it feeds 200-0VDC going the other direction. I have tried sequencing, putting in timers and a few other goofy things but I can not get the Vi to stop in the first For Loop, without the Vi performing the initial "5" to the second For Loop. Someone had mentioned using an event handler, in my previous post. I practiced for quite some time, trying to understand how to use an event handler but am not much the wiser. Any and all input would be greatly appreciated.

altenbach wrote:
ceilingwalker wrote:
You are autoindexing way too many thing between the two FOR loops I was doing this to create a data dependency, at least that was my thought process behind it. As far as the physical channels and VISA refnums, I did it this way so I didn't create more controls for the front panel. Being my first project, I am very certain my logic is flawed, this is why I like posting here and getting feedback from
 You have many visa sessions that (hopefully) never change during the execution of the loops, so why woold you turn them into an array of 11 identical elements just to autoidex them out again at the next loop. Change the tunnels to no autoindexing and things would look cleaner. Why are these session controls inside the loop? Are you expect them to be changeable during loop execution or would that screw up the results?
Wounld't it be easier to simply create an up&down ramp once and use a single FOR loop, autoindexing on the ramp? You have way too much duplicate code!!!
 If you don't want the second loop to run when the first one is ended prematurely with the stop button, put it in a case structure I tried a Case structure for the second For Loop. I couldn't find a way to change conditions that didn't affect the Vi's overall performance.
Then show us what you tried! That should be trivial to implement. Why would a case structure affect performance? Makes no sense!
Why would a case structure affect performance? Makes no sense! I used a boolean operator to change the state. When I used a false, it worked for that problem but shut down my Vi before the second For Loop. 
Wounld't it be easier to simply create an up&down ramp once and use a single FOR loop, autoindexing on the ramp? You have way too much duplicate code!!!  I tried using one For Loop to begin with but because I had to ramp up, then ramp down, I couldn't figure out how to use just one. I needed an Add function for the ramp up and a Subtract function for the ramp down.
Why are these session controls inside the loop? Are you expect them to be changeable during loop execution or would that screw up the results? No Sir, the values are not changed during operation. I did this because I wanted it to display the data on the front panel, during operation of the Vi. For display only.
 

Similar Messages

  • How to stop a "for" loop

    Hello,
    Do you know how I can stop a for loop ? because when I click on the stop switch on my front panel, the VI don't stop and continue to run the loop.
    Peter.
    Labview 2010
    Solved!
    Go to Solution.

    Peter,
    It sounds like you need a while loop, not a for loop. A button or switch does not traditionally control iterations of execution for a for loop.
    Please post your code so we may help better.
    -Chazzmd

  • How to pause and stop two "for loops" in an event

    Hi
    The main menu runs first and then goes to reading menu. After "Start Reading" button is pressed, the reading process will take readings.
    1) During reading process, if the "Pause Reading" button is pressed, I want that the two "for loops" are stopped and the two "for loop" counters do not reset. After the "Start Reading" button is pressed, the two "for loops" will continue to run.
    2) During reading process, if the "Stop Reading" button is pressed, I want that the two "for loops" are stopped and the two "for loop" counters are reset. After the "Start Reading" button is pressed, the two "for loops" will run again.
    The attached two VIs are simplified my real application. Any help will be appreciated.
    Thanks
    Steve
    Attachments:
    Main Menu Test.vi ‏9 KB
    Reading Menu Test.vi ‏23 KB

    You can't have those loops inside of the event structure.  Currently, when you press the start button, the reading has to finish before the event case finishes.  This will prevent the stop can cancel buttons from being processed by the event structure.
    You need another loop that can recieve commands from the event loop.  Look up the Queued Message Handler.  That should get you a good start on the command process.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Stopping a for loop abruptly

    Dear All,
              I have a doubt over here...In my frame, I have two buttons...one is "START" and the other is "STOP". If the "START" button is clicked, i am calling a method in which a "FOR LOOP" will start running for 100 times. If the "STOP" button is clicked, I should stop the said for loop, in the middle itself....how to do the above...
    any suggestions, solutions, ideas are higly appreciated...
    bye,
    Sakthivel S.

    u can use a boolean variable for that.in ur loop check that boolean if it is true perform the loop task.and when stop is pressed make that boolean false.and in ur loop if boolean is fale break the loop.i hope u r also using thread.sleep to minimize the processor usage.

  • Single start/stop button for looping movie

    Dear Friends,
    I apologize if this has been addressed already in the forum, as I have had no luck searching here or the web in general for a solution.
    I currently have a 23-frame multilayered single-scene animation designed to loop continuously which I would like to add to my portfolio. As such, I am adding a Play button, which I would like to toggle to a Stop (or Pause) button. I currently have an instance of the Play button ("playButton") created.
    (You can find this at pineboxmovingco.com/gear_redux.swf)
    Besides imploring your assistance in providing the code, I must also ask if this requires (and best practice for) inserting an additional frame at the beginning for the ActionScript, as well as where/what layer to add an instance of the Stop button. I would like the movie to be stopped by default, presenting the Play button, toggling to the Stop button, and back to the Play button, each upon release.
    Thank you so much in advance!
    Michael T
    Phila, PA

    So, Ned, insert the stop(); command - with no other code - on each keyframe of the MC like so:
    Then, return to Scene 1 and select the MC, inserting the code:
    With an additional "stop" command in the first frame:
    I must be missing something as it is continues to loop. Any further assistance would be greatly appreciated...
    Michael
    (UPDATE: Replaced second image with AS reflecting replacement of XXX with "1".)
    Message was edited by: turnerator

  • How to stop and start a for loop

    I've got code and a for loop running in a while loop.  What I need to do is simply pause the operation of the for loop until an requirement is met, and but maintain its iteration position throughout each pause interval (not necessarily timed, just paused until the next requirement is met).  I've tried wiring a boolean to the "continue if true" terminal of the for loop, but the iteration count restarts to 0 when the loop is started again.  Is there a way to stop the for loop, and continue at the particular iteration it is at?
    Solved!
    Go to Solution.

    Breakpoints, whether normal or conditional, are just meant for debugging of your code.  I had the sense from your question that the pausing you want to do is a part of normal operation of your code.  I would NOT recommend using a breakpoint for that situation.  It would bring up the block diagram showing the breakpoint when it occurs.  A user besides the programmer would not know what to do in that case.
     Yes, both the inner and outer loops would have shift registers.
    Putting a case structure with a small while loop inside the "Pausing Case" is doable.  It just depends on what you are doing or waiting for while the program operation is "paused".

  • Stopping for loop

    Hello
    I’m trying to stop a for loop of a subVI while it is still running. In the example you can see my problem. When I run the main VI the loop begins. When I press the stop button (in the main VI) the loop first finishes and after that the VI stops. Is it possible to program that when I push the button the VI immediately stops?
    Thank you in advance
    Attachments:
    Try.llb ‏35 KB

    becktho a écrit:
    Did you really stop a for loop? If so - could you attach the library as LV7.0? I'm wondering how you could have accomplished that.
    Sorry to disapoint you Becktho, but the loop was a while loop. And anyway, I would have replaced it !
    I agree with you, the possibility to leave a for loop would be of interest, although a while loop (actually a repeat-until loop) is easy to use. But the diagram could be simplified. Imagine : right-click the loop border, and select "create conditionnal exit", just bellow "add shift register"
    On another hand, having only two types (actually 3 with the timed loop) of loop structures is also quite simple. Have you noticed how beginners are confused by the number of different wire types ?
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        

  • Need help with a for loop

    Hi all
    I have a dir that has a list of folders that are created using php that my customers upload to. the PHP creates a new folder using the system date on the days that they upload. (using this format yyyymmdd)
    What I am trying to do is loop thou the folders and get todays folder and list the files that are in todays folder. I have been able to do this up to the point of if a customer folder does not have a folder called todays date.
    I know I need some sort of try / catch but don't know what.
    Can anyone help me please
    Thanks for you time and help in advance
    Craig
      public void getfolderList() {
        File dir = new File("/Users/craig/Documents/jBuilder_Epod/copy");
        File[] getFolderNames = dir.listFiles();
        if (getFolderNames != null) {
          for (int gf = 0; gf < getFolderNames.length; gf++) {
            String store = "" + getFolderNames[gf];
            if (!store.endsWith(".DS_Store")) { // This is a mac file name Only
              String folderName = "" + getFolderNames[gf];
              if (!store.endsWith(".DS_Store")) { // This is a mac file name Only
                //I need to have some sort of try and Catch here.
                // If there is no Folder called "todaysFileName" I need to go to the next folder
                //i.e. stop the for loop and go to next
                String setTodaysFileName = folderName + "/";
                String todaysFileName = setTodaysFileName + systemDate;
                File todaysFolder = new File(todaysFileName);
                File[] todaysFiles = todaysFolder.listFiles();
                for (int td = 0; td < todaysFiles.length; td++) {
                  todaysFileName = "" + todaysFiles[td];
                  System.out.println("There is no folder Today........" +
                                     todaysFileName);
      }

    A quick guess would be that after the sStatement
      File[] todaysFiles = todaysFolder.listFiles();todaysFiles is null if todaysFolder doesn't exist and you get a NullPointerException when trying to access todaysFiles.length in the following for-loop.
    If that doesn't help, please be a bit more precise what kind of Exception occurs...

  • FOR loop termination?

    Is there any way in LabView to terminate FOR loop from the inside
    before it executes N times? Something like "break" instruction in C. It
    seem like a simple question, but I couldn't find a simple solution :-).
    thanks,
    chris

    I know this is not exactly what you are asking for, but I will mention it anyway.
    There are two ways to stop a For Loop. The first is to use the auto-index like you are doing. The other is to wire a value to the N input before starting the
    loop. The loop will stop on the first occurence of EITHER of these methods. If you want the convenience of auto-indexing, but know that you will not want to
    process all of the values in the array, try to determine the quantity before entering the loop. Then wire that value to the N input. A value of 0 will prevent
    any iterations of the loop from executing.
    Good luck.
    Michael Munroe Mailto:[email protected]
    A Better Complete Development Engineering Firm
    San Mateo, CA 94403 ht
    tp://www.abcdefirm.com
    chris szybinski wrote:
    > this is exactly what I've done :-). But it would be much easier to be able to break the loop.
    > chris
    >
    > Harry King wrote:
    >
    > > In article <[email protected]>,
    > > chris szybinski wrote:
    > > >yes it is,
    > > >sometimes I need to run the loop 0 times. While Loop runs at lest one time, as the condition is checked at the end of the loop. One can build the logic to
    > > >run a While Loop 0 times, but in my case design becomes pretty complicated.
    > > >In other words I can accomplish what I want, but I hoped to simplify my VI.
    > > >best regards,
    > > >chris
    > >
    > > Perhaps you could put a select comparison function in there and send the
    > > results to the loop? WHile false, it will not run, and while true, it
    > > will. Just a thought without any background into your program.
    > >
    > > Harry
    Michael Munroe, ABCDEF
    Certified LabVIEW Developer, MCP
    Find and fix bad VI Properties with Property Inspector

  • For loop stop in sub vi from main vi?

    Hi! I want to control from my main vi a sub vi consisting of a stepped sine function generator. This sub vi has a for loop. The problem is that I want to have the option of terminating the loop in the sub vi from the main vi. I tryed using global variables or an event stucture. The problem is that, in both cases, the "stop" variable in my main vi is only updated after the loop terminates in the sub vi. Can anyone please help me? Thank you very much.
    Best regards,
    Diogo Montalvão (Lisbon, Portugal)

    hong2011 wrote:
    I found this thread very helpful. May I ask one thing - what is the purpose of the Occurrence?? If I try it without implementing the Occurrence (neither in main VI or subVI), labview crashes when the subVI completes its task or is stopped from the mainVI.
    A lot of things changed in the last 6 years, so this thread is a bit stale and there are a few other ways to do it. (For example we can have a FOR loop with a conditional terminal).
    You don't provide enough information to answer your question why it crashes. It would be more interesting to know what you are "using" and not what you are "not using". This is not something we can guess by elimination.
    LabVIEW should never crash, so please show us the code that crashes so NI can fix it. What LabVIEW version are you using?
    LabVIEW Champion . Do more with less code and in less time .

  • How to terminate or exit a for loop when the user clicks on stop button

    Actually my problem is to stop a loop when i click on stop button.
    example:i have two buttons 'start' and 'stop'
    in start buttom i wrote a for loop as
    dim i as integer
    For i=1 To 100000
    print i
    Next
    when i click on start buuton it prints 'i' value up tp 100000.
    my question is when i click on 'Stop' button the for loop has to terminate or Exit from the  loop and should stops the execution.
    Is it possible to termianate or Exit the 'for loop'
    PS.Shakeer Hussain
    Hyderabad

    I am unable to stop the loop and application not at all allowing to Press the Stop button.
    It seems like Hung, any advise ?
    Private Sub btnStart_Click(sender As Object, e As EventArgs) Handles btnStart.Click
            btnStop.Enabled = True
            btnSelectFile.Enabled = False
            btnStart.Enabled = False
            btnStop.Focus()
            Dim strFileName As String = txtFileName.Text.ToString
            Dim strLineText As String
            If System.IO.File.Exists(strFileName) = True Then
                Dim objReader As New System.IO.StreamReader(strFileName)
                While objReader.Peek() <> -1 And stopclick = False
                    strLineText = objReader.ReadLine()
                    MsgBox(strLineText, MsgBoxStyle.Information)
                    Application.DoEvents()
                    Thread.Sleep(My.Settings("strDelay") * 1000)
                    'System.Diagnostics.Process.Start(My.Settings("strFireFoxLocation"), strLineText)
                End While
            End If
        End Sub
        Private Sub btnStop_Click(sender As Object, e As EventArgs) Handles btnStop.Click
            stopclick = True
            btnSelectFile.Enabled = True
            btnStart.Enabled = True
            btnStop.Enabled = False
        End Sub
    Raman Katwal
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

  • I have a for loop inside of while loop.when i press stop for while loop, i also would like to stop for loop.how can i solve this problem?thanks

    i have a for loop inside of while loop.when i press stop for while loop, i also would like to stop for loop.how can i solve this problem?thanks

    Hi fais,
    Following through with what JB suggested. The steps involved in replacing the inner for loop with a while loop are outlined below.
    You can replace the inner for loop with a while by doing the following.
    1) Right-click of the for loop and select "Repalce" then navigate to the "while loop".
    2) Make sure the tunnels you where indexing on with the for loop are still indexing.
    3) Drop an "array size" node on your diagram. Wire the array that determines the number of iterations your for loop executes into this "array size".
    4) Wire the output of the array size into the new while loop.
    5) Set the condition terminal to "stop if true".
    6)Drop an "OR" gate inside the while loop and wire its output to the while loops condition terminal.
    7) C
    reate a local of the boolean "stop" button, and wire it into one of the inputs of your OR gate. This will allow you to stop the inner loop.
    8) Drop a "less than" node inside the inner while loop.
    9) Wire your iteration count into the bottom input of the "less than".
    10) Wire the count (see step 4 above) into the top input of the less than. This will stop the inner loop when ever the inner loop has processed the last element of your array.
    Provided I have not mixed up my tops and bottoms this should accomplish the replacement.
    I will let others explain how to takle this task using the "case solution".
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • How to make a button to stop and run a for loop?

    How to make a button to stop and run a for loop?  and if it is stopped it shall start from where i t stopped.

    Your VI has some very fundamental flaws.
    The start/stop button is outside the FOR loop, thus it will NOT get read during execution of the FOR loop, but only before the FOR loop starts. Think dataflow!
    Thus the terminal of the start/stop button belongs inside the FOR loop.
    Your FOR loop iterates 20x, which probably takes about a nanosecond. You will NOT be fast enough to reliably press the start/stop button during a specific iteration of the FOR loop.
    Your code does not "stop and run" a FOR loop (sic). The loop always spins, but executes an empty case when "Stopped". I guess that's what you actually want?
    Once you solve (2), the x indicator will contain a random value whenever you "stop".
    As soon as the 20 iterations complete, the outer while loop spin an things start over, another nanosecond later.
    Place e.g. a 500ms wait inside the FOR loop to solve this.
    Don't place terminals of indicators on top of formula nodes.
    Your formula does not produce any output, so really has no purpose.
    Use a real "stop" button to terminate the while loop (mechanical action: latch when released). Right now you are using a plain switch, which does not reset to false before the next run. This means that you need to manually reset it before running the program again.
    It is oftern useful to operate the VI in execution highlighting mode. You will immediately see that your button does not get read during execution of the FOR loop. Try it!
    LabVIEW Champion . Do more with less code and in less time .

  • Stopping output tasks properly before exiting a For-loop

    Hi,
    I've been having some trouble exiting a For-loop conditionally. The problem is that when the loop is stopped conditionally (a button is pressed) the DAQ (NI USB 6353) outputs get stuck to whatever value they were in. I tried stopping the DAQ Assistant output task (1 sample on demand)  before exiting the loop but that didn't solve the problem. Should this perhaps be done one iteration before exiting the loop or can it be done in the same iteration round?
    What would be the "right" way to exit a for loop with output tasks so that the output signals would be 0V after exiting? I know that I could "force" feed the DAQ Assistant with 0V control before exiting but in this case that would be quite difficult...
    Any ideas? Help is appriciated.

    Yes, I get it... However at this point I don't think that's an option.
    Would this kind of solution work? ( I am not able to test all possible solutions in the real system which is why I would like to get a confirmation first)
    The idea is to connect the output of the "Or" port to the "Stop" -ports of the DAQ Assistants in the loop.
    Edit. Will the output automatically go to 0V if I just stop the task? I am not really sure about this.
    Thank you.
    Attachments:
    exit-loop.jpg ‏8 KB

  • Stopping and Continuing a For Loop

    I have a problem on looping. This is a game of Whack the Mole. First, there is a for loop that is in charge of generating different hole positions for my moles. I want it so that the loop will (1) Generate a number (2) Stop the generating (3) Based on the number that was just generated, run a function for it. Once done running the function, then (4)Start the second round of generating another number......and it goes on for 9 rounds. I have my code here.
    var molePosX:Array = [166.90, 494.8, 810.7];
    var molePosY:Array = [282.55, 512.45, 730.35];
    var moleInUse:Boolean = false;
    if (moleInUse == false){
    for(var i:uint = 1; i<10; i++){
              var randomHole:Number = Math.floor(Math.random()*10)+1; //Generate 10 number
              trace(randomHole);
              switch (randomHole){
              case 1: trace("1");
              moleRun(molePosX[0],molePosY[0]);
              break;
              case 2: trace("2");
              moleRun(molePosX[1],molePosY[0]);
              break;
              case 3: trace("3");
              moleRun(molePosX[2],molePosY[0]);
              break;
              case 4: trace("4");
              moleRun(molePosX[0],molePosY[1]);
              break;
              case 5: trace("5");
              moleRun(molePosX[1],molePosY[1]);
              break;
              case 6: trace("6");
              moleRun(molePosX[2],molePosY[1]);
              break;
              case 7: trace("7");
              moleRun(molePosX[0],molePosY[2]);
              break;
              case 8: trace("8");
              moleRun(molePosX[1],molePosY[2]);
              break;
              case 9: trace("9");
              moleRun(molePosX[2],molePosY[2]);
              break;
              case 10: trace("10");
              break;
              function moleRun(xPos:Number,yPos:Number){
                        moleInUse = true;
                        var mole2:Mole = new Mole();
                        mole2.x = xPos;
                        mole2.y = yPos;
                        addChild(mole2);
                        moleInUse = false;
    Thank you very much!

    i'm not sure you want to do that without staggering your mole creation but if you do, you can use:
    var molePosX:Array = [166.90, 494.8, 810.7];
    var molePosY:Array = [282.55, 512.45, 730.35];
    createMoleF(9);
    function createMoleF(n:int):void{
    for(var i:uint = 0; i<n; i++){
              moleRun(Math.floor(Math.random()*molePosX.length),Math.floor(Math.random()*molePosY));
              function moleRun(xPos:Number,yPos:Number){
                        var mole2:Mole = new Mole();
                        mole2.x = xPos;
                        mole2.y = yPos;
                        addChild(mole2);
    Thank you very much!

Maybe you are looking for

  • Stolen 4s returned but can't get it working after reset

    My fone was solen in November and returned by the police yesterday. The thief had changed all setting and named the fone as his. I had it on FIND MY FONE but no luck but yesterday it deleted it. The screen is black with the circle icon going round .

  • How to charge for the first time?

    I bought myself a new iPhone and this was from the store, not from someone else, so how should I charge it for the first time? Should I wait when iPhone loads out till blank screen and the charge it to 100%? How do you charge your iPhone by the way,

  • How to setup project property in 9iJdeveloper?

    i don't know how to setup the project property, although i have experience with jdev3.1. i want to run a helloworld.jsp. the project name is myProject. the files i have helloworld.jsp helloworldBean.java helloworldProvider.java the data "hello world"

  • I can't get rid of my Mint search add-on and I can't disable it.

    Firefox Version 3.6.13 I do not want the MyFreeMint search at the bottom of my display. Unfortunately I can neither disable nor uninstall it in my add-ons. Help would be much appreciated. Steve L

  • Open Browser from My Application

    I have created a Notepad in Java.I want to create an option which should open the browser and pass the contents of the Notepad to it.Can anyone suggest how do i go about doing this??Thanx in Advance