Why won't for loop execute?

Can anyone tell me why this for loop won't execute in "Security System".  Basically I was practicing for the  CLD exam by writing the "Security System" practice exam.  I wanted to try the Event-Driven State Machine with a queue.  My problem is that in the "Check Alarm", "Check Bypass", and "Check Tamper" states, I have a for loop which is indexed with 4 - 6 element arrays.  The for loop will not execute 6 times.  It won't even execute once.  It just skips over the for loop and outputs all boolean falses and zeros for the numeric values.  Is this a Labview glitch of some sort?
Thanks for any replies.
Matt Koebel
Attachments:
Security System.zip ‏108 KB

tst wrote:
Without looking at the code, my guess would be that one of the indexing inputs into the loop is 0.
More precisely ".. is an array of size zero.
(1) Go to yout three boolean arrays and click on the 6th element to make the arrays size=6 with all FALSE. now make current values default and save the VI.
(2) You also need to wire the boolean arrays across all event cases  to ensure the current values are kept in the shift register. RIght now a change in one array resets the others to an empty array again.
(3) now initialize a boolean array containing six FALSE and initialize the shift registers with it. 
Message Edited by altenbach on 10-22-2008 11:55 AM
LabVIEW Champion . Do more with less code and in less time .

Similar Messages

  • Why Isn't the for loop executing?

    here's the code,the for loop isn't executing,can anyone trouble shoot?
    import acm.program.ConsoleProgram;
    public class AddIntegerList extends ConsoleProgram {
    public void run(){
         for(int c=0;c<5;c++);{
         println("This is a programe to divide 2 numbers");
    double i = readDouble("enter num1: ");     
    double x = readDouble("enter num2: ");
    double ans = i/x;
    println("The answer to your division Is "+ans+ "");
              } by the way,this Is the first piece of java code that I have written. :D
    Edited by: Parastar on Oct 21, 2009 4:20 AM

    I dont think there should be a semicolon at the end of this
    for(int c=0;c<5;c++); Remove it and try running the program.
    Edited by: A.J.Bharanidharan on Oct 21, 2009 4:53 PM

  • Statement error in for loop noobq

    Hi
    Could anyoe tell me why this wont work? Its supposed to count upp to tal in the first one and then count down from tal in the second and its the second one that dont work. I get a statement error for the text i put in between stars (supposed to be bold but i dont know..)
    thanks
    class r?knaa {
        public static void main(String[] args) {
            new r?knaa().run();
        void run() {
         int tal = Keyboard.nextInt ("Ange ett tal ? s? ska vi r?kna...(^_^): ");
         for (int upp = 1; upp <= tal; upp = upp + 1) {
             System.out.print ( upp+ " " );
         System.out.println (" ");
         System.out.println (" ");
         for (*tal*; tal > 0; tal = tal -1 ){
             System.out.print ( tal+ " " );
    }Edited by: gibitlib on Feb 19, 2010 3:02 PM

    jverd wrote:
    sharkura wrote:
    I assumed that it would decrement after the block of statements associated with the while loop, as is true with the for loop.Not sure what you mean by "as is true with the for loop", but I'm catching a hint of a very common misconception about the post-inc/dec operators.
    A LOT of people think that post-inc/dec means "last step in the statement" or "after everything else has been done" or something like that. That kind of thiiking is just black magic hocus pocus and serves no purposeI don't think I thiik like that, Jeff. I've never used a post-inc operator in a while loop. Certainly, if I felt a need to do so, I would test it, and try to understand why it works the way it does. Empirically, I know that given the following for loop:
    for ( int i = 0; i < limit; i++ )
      ... some statements
    }the incrementation of i occurs after the statements in the block execute. It may be specific to the for loop that the third statement in the for loop executes after the block of statements, in which case
    for ( int i = 0; i < limit; ++i )
      ... some statements
    }would work the same, and you can bet I will test that.
    I did make an assumption last night, and did not test it. That is not typical of me. I do resent somewhat the accusation of black magic hocus pocus. My last statement in that post was:
    sharkura wrote:
    I'll have to play with this some.Implicit in that remark was my intent to read more about pre/post decrementation and experiment until I more fully understood it. You have pointed out my lack of complete understanding, and, odd as it may seem, I appreciate that. I do log into these forums, partly, to improve my understanding of java.
    {?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Trace For -Loop variable

    I am trying to trace for-loop . The counter variable does not show the last value in the stack frame variables. For example if my code is as:
    public class ForCounter
    public static void main(String args[])
    for (int i =0;i<=5;i++)
    System.out.println(i);
    }My output is as:
    Event Location =ForCounter:5
    ForCounter.java:5 in method main() ****
    java.lang.String[] args = instance of java.lang.String[0] (id=38)
    Event Location =ForCounter:7
    ForCounter.java:7 in method main() ****
    java.lang.String[] args = instance of java.lang.String[0] (id=38)
    int i = 0
    Event Location =ForCounter:5
    ForCounter.java:5 in method main() ****
    java.lang.String[] args = instance of java.lang.String[0] (id=38)
    int i = 0
    Event Location =ForCounter:7
    ForCounter.java:7 in method main() ****
    java.lang.String[] args = instance of java.lang.String[0] (id=38)
    int i = 1
    Event Location =ForCounter:5
    ForCounter.java:5 in method main() ****
    java.lang.String[] args = instance of java.lang.String[0] (id=38)
    int i = 1
    Event Location =ForCounter:7
    ForCounter.java:7 in method main() ****
    java.lang.String[] args = instance of java.lang.String[0] (id=38)
    int i = 2
    Event Location =ForCounter:5
    ForCounter.java:5 in method main() ****
    java.lang.String[] args = instance of java.lang.String[0] (id=38)
    int i = 2
    Event Location =ForCounter:7
    ForCounter.java:7 in method main() ****
    java.lang.String[] args = instance of java.lang.String[0] (id=38)
    int i = 3
    Event Location =ForCounter:5
    ForCounter.java:5 in method main() ****
    java.lang.String[] args = instance of java.lang.String[0] (id=38)
    int i = 3
    Event Location =ForCounter:7
    ForCounter.java:7 in method main() ****
    java.lang.String[] args = instance of java.lang.String[0] (id=38)
    int i = 4
    Event Location =ForCounter:5
    ForCounter.java:5 in method main() ****
    java.lang.String[] args = instance of java.lang.String[0] (id=38)
    int i = 4
    Event Location =ForCounter:7
    ForCounter.java:7 in method main() ****
    java.lang.String[] args = instance of java.lang.String[0] (id=38)
    int i = 5
    Event Location =ForCounter:5
    ForCounter.java:5 in method main() ****
    java.lang.String[] args = instance of java.lang.String[0] (id=38)
    int i = 5
    Event Location =ForCounter:10
    ForCounter.java:10 in method main() ****
    java.lang.String[] args = instance of java.lang.String[0] (id=38)
    *{color:#ff0000}the variable i doesnt get the value 6 as I expected in the comparison process? Any idea How can I see that?*
    *As I understood , the variable i values incremented and at the last step when the comparison failed the body of the for loop doesnt execute. ( 6 is not <= 5){color}*

    I am posting the code here to see what I mean. I need to compare these 2 programs that produces the same output. The stack frame trace must be the sme, but when I run the code on them. it doesn't work. I wish to know why in the for loop the value of i doesn't reach the value 4 as it showes in normal debugging. I am really thanx for your help.
    The two programs that I am comparing is:
    1-
    public class WhileCounter
         public static void main(String args[])
              int i = 0;
             while ( i <= 3)
                   System.out.println(i);
                  i++;
    and
    2-
    public class ForCounter
         public static void main(String args[])
              for (int i =0;i<=3;i++)
                   System.out.println(i);
    The Trace program that I am using is :
    // ****** Trace.java ******
    import java.io.*;
    import java.util.*;
    import com.sun.jdi.*;
    import com.sun.jdi.request.*;
    import com.sun.jdi.event.*;
    import com.sun.jdi.connect.*;
    class Trace {
        // Running remote VM
        private final VirtualMachine vm;
        // Thread transferring remote error stream to our error stream
        private Thread errThread = null;
        // Thread transferring remote output stream to our output stream
        private Thread outThread = null;
         * main
        public static void main(String[] args) {
         new Trace(args);
         * Launch target VM.
         * Generate the trace.
        Trace(String[] args) {
         PrintWriter writer = new PrintWriter(System.out);
         // Launch target VM - Foo is the class to be executed
            vm = launchTarget("WhileCounter");
            generateTrace(writer);
         * Generate the trace.
         * Enable events, start thread to display events,
         * start threads to forward remote error and output streams,
         * resume the remote VM, wait for the final event, and shutdown.
        void generateTrace(PrintWriter writer) {
            vm.setDebugTraceMode(VirtualMachine.TRACE_NONE);
            EventThread eventThread = new EventThread(vm, writer);
            eventThread.start();
            redirectOutput();
            vm.resume();
            // Shutdown begins when event thread terminates
         try {
             eventThread.join();
             errThread.join(); // Make sure output is forwarded
             outThread.join(); // before we exit
         } catch (InterruptedException exc) {
             // we don't interrupt
         writer.close();
         * Launch target VM.
         * Forward target's output and error.
        VirtualMachine launchTarget(String mainArgs) {
         LaunchingConnector connector = findLaunchingConnector();
         Map arguments = connectorArguments(connector, mainArgs);
            try {
             return connector.launch(arguments);
            } catch (IOException exc) {
                throw new Error("Unable to launch target VM: " + exc);
            } catch (IllegalConnectorArgumentsException exc) {
                throw new Error("Internal error: " + exc);
            } catch (VMStartException exc) {
                throw new Error("Target VM failed to initialize: " +
                       exc.getMessage());
        void redirectOutput() {
            Process process = vm.process();
            // Copy target's output and error to our output and error.
            errThread = new StreamRedirectThread("error reader", process.getErrorStream(), System.err);
            outThread = new StreamRedirectThread("output reader",process.getInputStream(), System.out);
            errThread.start();
            outThread.start();
         * Find a com.sun.jdi.CommandLineLaunch connector
        LaunchingConnector findLaunchingConnector() {
            List<Connector> connectors = Bootstrap.virtualMachineManager().allConnectors();
            for(Connector connector: connectors)
                if (connector.name().equals("com.sun.jdi.CommandLineLaunch"))
                    return (LaunchingConnector)connector;
            throw new Error("No launching connector");
         * Return the launching connector's arguments.
        Map connectorArguments(LaunchingConnector connector, String mainArgs) {
            Map arguments = connector.defaultArguments();
            Connector.Argument mainArg =
                            (Connector.Argument)arguments.get("main");
            if (mainArg == null) {
                throw new Error("Bad launching connector");
         mainArg.setValue(mainArgs);
         // Need a VM that supports watchpoints
         Connector.Argument optionArg = (Connector.Argument)arguments.get("options");
         if (optionArg == null) {
             throw new Error("Bad launching connector");
         optionArg.setValue("-classic");
         return arguments;
    import java.io.*;
    import java.util.*;
    import com.sun.jdi.*;
    import com.sun.jdi.request.*;
    import com.sun.jdi.event.*;
    import com.sun.jdi.connect.*;
    class EventThread extends Thread {
        private final VirtualMachine vm;   // Running VM
        private final PrintWriter writer;  // Where output goes
        private boolean connected = true;  // Connected to VM
        private boolean vmDied = true;     // VMDeath occurred
        // Maps ThreadReference to ThreadTrace instances
        private Map traceMap = new HashMap();
        EventThread(VirtualMachine vm, PrintWriter writer) {
            super("Event-Handler");
            this.vm = vm;
            this.writer = writer;
         * Run the event handling thread.
         * As long as we are connected, get event sets off
         * the queue and dispatch the events within them.
        public void run() {
            EventQueue queue = vm.eventQueue();
            while (connected) {
                try {
                    EventSet eventSet = queue.remove();
              for(Event e: eventSet)
                  handleEvent(e);
                    eventSet.resume();
                } catch (InterruptedException exc) {
                    // Ignore
                } catch (VMDisconnectedException discExc) {
                    break;
         * This class keeps context on events in one thread.
         * In this implementation, context is the indentation prefix.
        class ThreadTrace {
            final ThreadReference thread;
         ThreadTrace(ThreadReference thread) {
                this.thread = thread;
                // Create step event which will step through all lines
                EventRequestManager mgr = vm.eventRequestManager();
                StepRequest req = mgr.createStepRequest(thread,
                                                        StepRequest.STEP_LINE,
                                                        StepRequest.STEP_INTO);
                req.setSuspendPolicy(EventRequest.SUSPEND_ALL);
                 req.addClassFilter("WhileCounter");
                req.enable();
         private void println(String str) {
             writer.println(str);
         void printStackFrame(StackFrame sf) {
             try {
              for(LocalVariable localvar: sf.visibleVariables()) {
                  println("Local variable: " + localvar.name() + " = "+sf.getValue(localvar));
             } catch(AbsentInformationException e) {
              println("Got AbsentInformationException");
         void stepEvent(StepEvent event)  {
             try {
              if(!event.thread().frame(0).location().sourceName().equals("WhileCounter.java"))
                  return;
             } catch(Exception e) {
              return;
             try {
              StackFrame sf = event.thread().frame(0);
              println("\n**** " + sf.location().sourceName() +
                   ":" + sf.location().lineNumber() +
                   " in method " + sf.location().method().name() + "() ****");
              for(StackFrame s: event.thread().frames()) {
                  printStackFrame(s);
             } catch(Exception e) {
              //foo
         * Returns the ThreadTrace instance for the specified thread,
         * creating one if needed.
        ThreadTrace threadTrace(ThreadReference thread) {
         return (ThreadTrace)traceMap.get(thread);
         * Dispatch incoming events
        private void handleEvent(Event event) {
         if (event instanceof StepEvent) {
             stepEvent((StepEvent)event);
         } else if(event instanceof VMStartEvent) {
             startEvent((VMStartEvent)event);
        // Create entry in traceMap
        private void startEvent(VMStartEvent event) {
         traceMap.put(event.thread(), new ThreadTrace(event.thread()));
        // Forward event for thread specific processing
        private void stepEvent(StepEvent event)  {
         threadTrace(event.thread()).stepEvent(event);
    import java.io.*;
    import java.util.*;
    import com.sun.jdi.*;
    import com.sun.jdi.request.*;
    import com.sun.jdi.event.*;
    import com.sun.jdi.connect.*;
    * StreamRedirectThread is a thread which copies it's input to
    * it's output and terminates when it completes.
    class StreamRedirectThread extends Thread {
        private final Reader in;
        private final Writer out;
        private static final int BUFFER_SIZE = 2048;
         * Set up.
         * @param name  Name of the thread
         * @param in    Stream to copy from
         * @param out   Stream to copy to
        StreamRedirectThread(String name, InputStream in, OutputStream out) {
         super(name);
         this.in = new InputStreamReader(in);
         this.out = new OutputStreamWriter(out);
         setPriority(Thread.MAX_PRIORITY-1);
        public void run() {
            try {
             char[] cbuf = new char[BUFFER_SIZE];
             int count;
             while ((count = in.read(cbuf, 0, BUFFER_SIZE)) >= 0) {
              out.write(cbuf, 0, count);
                out.flush();
         } catch(IOException exc) {
             System.err.println("Child I/O Transfer - " + exc);
    The output from WhileCounter.java
    --------------------Configuration: <Default>--------------------
    Warning: classic VM not supported; client VM will be used
    0
    1
    2
    3
    **** WhileCounter.java:5 in method main() ****
    Local variable: args = instance of java.lang.String[0] (id=29)
    **** WhileCounter.java:6 in method main() ****
    Local variable: args = instance of java.lang.String[0] (id=29)
    Local variable: i = 0
    **** WhileCounter.java:8 in method main() ****
    Local variable: args = instance of java.lang.String[0] (id=29)
    Local variable: i = 0
    **** WhileCounter.java:9 in method main() ****
    Local variable: args = instance of java.lang.String[0] (id=29)
    Local variable: i = 0
    **** WhileCounter.java:6 in method main() ****
    Local variable: args = instance of java.lang.String[0] (id=29)
    Local variable: i = 1
    **** WhileCounter.java:8 in method main() ****
    Local variable: args = instance of java.lang.String[0] (id=29)
    Local variable: i = 1
    **** WhileCounter.java:9 in method main() ****
    Local variable: args = instance of java.lang.String[0] (id=29)
    Local variable: i = 1
    **** WhileCounter.java:6 in method main() ****
    Local variable: args = instance of java.lang.String[0] (id=29)
    Local variable: i = 2
    **** WhileCounter.java:8 in method main() ****
    Local variable: args = instance of java.lang.String[0] (id=29)
    Local variable: i = 2
    **** WhileCounter.java:9 in method main() ****
    Local variable: args = instance of java.lang.String[0] (id=29)
    Local variable: i = 2
    **** WhileCounter.java:6 in method main() ****
    Local variable: args = instance of java.lang.String[0] (id=29)
    Local variable: i = 3
    **** WhileCounter.java:8 in method main() ****
    Local variable: args = instance of java.lang.String[0] (id=29)
    Local variable: i = 3
    **** WhileCounter.java:9 in method main() ****
    Local variable: args = instance of java.lang.String[0] (id=29)
    Local variable: i = 3
    **** WhileCounter.java:6 in method main() ****
    Local variable: args = instance of java.lang.String[0] (id=29)
    Local variable: i = 4
    **** WhileCounter.java:12 in method main() ****
    Local variable: args = instance of java.lang.String[0] (id=29)
    Local variable: i = 4
    Process completed.
    The output for ForCounter.java is
    --------------------Configuration: <Default>--------------------
    Warning: classic VM not supported; client VM will be used
    0
    1
    2
    3
    **** ForCounter.java:5 in method main() ****
    Local variable: args = instance of java.lang.String[0] (id=29)
    **** ForCounter.java:7 in method main() ****
    Local variable: args = instance of java.lang.String[0] (id=29)
    Local variable: i = 0
    **** ForCounter.java:5 in method main() ****
    Local variable: args = instance of java.lang.String[0] (id=29)
    Local variable: i = 0
    **** ForCounter.java:7 in method main() ****
    Local variable: args = instance of java.lang.String[0] (id=29)
    Local variable: i = 1
    **** ForCounter.java:5 in method main() ****
    Local variable: args = instance of java.lang.String[0] (id=29)
    Local variable: i = 1
    **** ForCounter.java:7 in method main() ****
    Local variable: args = instance of java.lang.String[0] (id=29)
    Local variable: i = 2
    **** ForCounter.java:5 in method main() ****
    Local variable: args = instance of java.lang.String[0] (id=29)
    Local variable: i = 2
    **** ForCounter.java:7 in method main() ****
    Local variable: args = instance of java.lang.String[0] (id=29)
    Local variable: i = 3
    **** ForCounter.java:5 in method main() ****
    Local variable: args = instance of java.lang.String[0] (id=29)
    Local variable: i = 3
    **** ForCounter.java:10 in method main() ****
    Local variable: args = instance of java.lang.String[0] (id=29)
    Process completed.

  • For-Loops: The question no one asks.

    Why don't For-Loops have a premature exit capability --- i.e. why didn't
    NI include the exit capability that exists in other languages? Is it a dataflow
    thing? I don't see how. Just curious.

    Jay,
    I have to say I`m no programming Guru, but isn`t a State Maschine based on a
    case (Switch) statement? This statement does allow the user to hop to and
    fro within a certian pre-defined space, but the use of a GOTO is, as far as
    I am aware, not limited to a particular region of the code. At least with a
    switch statement (Case) the beginning point of each "choice" is well defined
    and fixed, therefore reducing the change of mistakes.
    just my 2 cents
    Shane
    Jay schrieb in Nachricht <[email protected]>...
    >
    >Hey, Tim. You say:
    >
    >>I believe that the loop exit capability wasn't included because it was
    considered
    >bad programming practice, like using goto's.
    >
    > That's funny. How can it be any worse (or different) than putt
    ing exit
    >logic into a While-Loop? As for Goto's, they're the basic logic behind the
    >much revered State Machine, and no one seems to mind that. If you're not
    >careful, State Machines can wind up producing some pretty good spaghetti
    >code, just like any text-based code can do.
    >
    >Jay
    >
    >>> Original message: Why don't For-Loops have a premature exit capability
    >--- i.e. why didn't NI include the exit capability that exists in other
    languages?
    > Is it a dataflow thing? I don't see how. Just curious.
    Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)

  • 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

  • For loop prob - PLEASE HELP!

    I am having problems with a for loop. This for loop is nested within some other for loop. the problem I'm having is that the for loop executes once and then exits to execute the outer for loop. my initial reaction was that my condition (in the for loop ) was false the second time round thus resulting in the exit. I'm usually told to paste some code so i'll do that:
    for (int i=0; i<row.size(); ++i){
      for (int all = 1; all < row.size();all++){
       try{          
         for (int k=0; k< column.size();  k++){
         System.out.println(" column size " + column.size());
         Long longObject1 = (Long)((Vector)row.get(i)).get(k);
         System.out.println(" getting" + longObject1);
    }                              �
         for (int k=0; k< column.size(); k++){ is the loop causing me problems.  column.size() evaluates to 2 so what is the problem?

    No I don't think there is another thread effecting column -I have even placed a Println to show what the value of column is. At present the value of column is 2 so the for loop should execute twice.
    I have a catch block which catches ClassCastException. The second element in row is not null. Furthermore, the size of count is 2 so the for loop should execute twice.
    yes the first element in row is another vector. (Row is a vector of vectors). I've looked at the other suggestions too but even after considering these i am left with the same problem. Any other suggestions? I could do with all the help I can get. Thanks

  • Stacked sequence inside for loop question

    Hi everyone,
    I am new to LabVIEW and I just want to make a for loop with a stack sequence inside. I want it so that when the for loop executes for the n-th time, the stacked sequence is at the n-th frame (because each frame contains different tasks to be carried out). Is this possible? or is there an alternative equivalent method? Please help me out! Thanks!!

    Thank you Norbert for the words of advice.
    Try to avoid Stacked Sequence Structures at all cost.  They are a nightmare to deal with when maintaining the code and they do not offer simple scalability, especially if you need to deal with parallelism.
    As Norbert suggested, State Machines is the way to go.  Try to avoid naming covention such as 1...2...3...4...5.......9999.  Give the name of each case based on what that case does.  Create a TypeDef Control for the state selector (you'll thank me after having changed it for the 5th time   ).
    There are probably 100's of examples in this forum.
    RayR

  • My for loop pauses after completion of the prescribed number of loops.

    I've created a FOR loop to alternate the value of an analog output between two setpoints. Since there are only 2 setpoints there need only be 2 complete 'loops'. After these two loops are complete the program pauses before continuing restarting the loop. I used the FOR loop instead of a WHILE loop because I use the value of the loop number to change the value of the output.

    Maybe you are initializing DAQ before the For Loop executes or you have a Wait timer outside of your For Loop.

  • For loop array index not from 0

    HI!
    I have an array that is wired into a For Loop. Inside the For Loop there is already a single Array content available as there is this autoindexing feature (?). I do want to change the Array from a certain position different from 0 onwards to the end e.g. change positions 4, 5 and 6 in a for loop executing 3 times. But the for loop and the autoindexing feature start at 0. Can I change this in an elegant way. At the moment I'm running thru the hole array and begin changing at a certain position.

    Yes, disable autoindexing on the tunnel and use "index array" inside the loop. Use [n]+4 as index and wire a "3" to the loop count in your particular example.
    If you want to keep the entire array and just replace a few elements with updated values, the array needs to be fed in via a shift register. Write the new elements at the desired position using "replace array subset" (see attached very simple example).
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    ReplaceSomeArrayElements.gif ‏3 KB

  • Trouble with "for loop"

    Hi all,
    how can I fix this problem
    Rookie; LV 2011 on WIN 7
    Solved!
    Go to Solution.

    Jkhourigan wrote:
    Disable indexing on the right hand side of the for loop.
    Consider using shift registers instead.
    That will indeed clear the error message but then your For loop will want to know how many times to iterate and I suspect you will only want to iterate once so why use the For loop?
    Toss it.
    If you were using the For loop to ensure a delay ... after (?) the transmit ...
    THere is no guarentee the wait will happen after since the is no data flow dependencies. If wan to delay after, add another frame between Xmit and rcv. Please note that I am talking about the most basic data flow ideas that drive LabVIEW and in serious coding data flow alone should drive the program execution and seq frames are used sparingly.
    Quesion anything I said above. Since the paradigm shift for LV may be weird.
    You at least have gotten past the "how do I wire things up?" challenge that frustrated me when I got started.
    Have fun!
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • Functions in a For Loop defining objects from an Array. . .Why Won't This Work?!

    I'm trying to put these functions into a Loop to conserve
    space. Why won't this work?
    .

    Yeah, sly one is right. You can not have the "i" inside the
    onRollOver function, what you have to do is: As the movieClip class
    is dynamic you can create a property of the movieClip which stores
    the value if the "i". And then, inside the onRollOver function, you
    have to make reference to that property.
    for (i=0; i<2; i++) {
    this.regArray
    .iterator = i;
    this.regArray.onRollOver = function () {
    showRegion(regArray[this.iterator]);
    this.regArray
    .onRollOut = function () {
    hideRegion(regArray[this.iterator]);

  • How to optimize the select query that is executed in a cursor for loop?

    Hi Friends,
    I have executed the code below and clocked the times for every line of the code using DBMS_PROFILER.
    CREATE OR REPLACE PROCEDURE TEST
    AS
       p_file_id              NUMBER                                   := 151;
       v_shipper_ind          ah_item.shipper_ind%TYPE;
       v_sales_reserve_ind    ah_item.special_sales_reserve_ind%TYPE;
       v_location_indicator   ah_item.exe_location_ind%TYPE;
       CURSOR activity_c
       IS
          SELECT *
            FROM ah_activity_internal
           WHERE status_id = 30
             AND file_id = p_file_id;
    BEGIN
       DBMS_PROFILER.start_profiler ('TEST');
       FOR rec IN activity_c
       LOOP
          SELECT DISTINCT shipper_ind, special_sales_reserve_ind, exe_location_ind
                     INTO v_shipper_ind, v_sales_reserve_ind, v_location_indicator
                     FROM ah_item --464000 rows in this table
                    WHERE item_id_edw IN (
                             SELECT item_id_edw
                               FROM ah_item_xref --700000 rows in this table
                              WHERE item_code_cust = rec.item_code_cust
                                AND facility_num IN (
                                       SELECT facility_code
                                         FROM ah_chain_div_facility --17 rows in this table
                                        WHERE chain_id = ah_internal_data_pkg.get_chain_id (p_file_id)
                                          AND div_id = (SELECT div_id
                                                          FROM ah_div --8 rows in this table
                                                         WHERE division = rec.division)));
       END LOOP;
       DBMS_PROFILER.stop_profiler;
    EXCEPTION
       WHEN NO_DATA_FOUND
       THEN
          NULL;
       WHEN TOO_MANY_ROWS
       THEN
          NULL;
    END TEST;The SELECT query inside the cursor FOR LOOP took 773 seconds.
    I have tried using BULK COLLECT instead of cursor for loop but it did not help.
    When I took out the select query separately and executed with a sample value then it gave the results in a flash of second.
    All the tables have primary key indexes.
    Any ideas what can be done to make this code perform better?
    Thanks,
    Raj.

    As suggested I'd try merging the queries into a single SQL. You could also rewrite your IN clauses as JOINs and see if that helps, e.g.
    SELECT DISTINCT ai.shipper_ind, ai.special_sales_reserve_ind, ai.exe_location_ind
               INTO v_shipper_ind, v_sales_reserve_ind, v_location_indicator
               FROM ah_item ai, ah_item_xref aix, ah_chain_div_facility acdf, ah_div ad
              WHERE ai.item_id_edw = aix.item_id_edw
                AND aix.item_code_cust = rec.item_code_cust
                AND aix.facility_num = acdf.facility_code
                AND acdf.chain_id = ah_internal_data_pkg.get_chain_id (p_file_id)
                AND acdf.div_id = ad.div_id
                AND ad.division = rec.division;ALSO: You are calling ah_internal_data_pkg.get_chain_id (p_file_id) every time. Why not do it outside the loop and just use a variable in the inner query? That will prevent context switching and improve speed.
    Edited by: Dave Hemming on Dec 3, 2008 9:34 AM

  • For Loop Will Not Execute

    I have been a software engineer for a number of years now, and thus far I have never come across any coding issues that truly merit a post such as this. Someone has almost always run across the issue before, so there is no need to reinvent the wheel, or solution as it were.
    However, a number of times I have run across instances where the JRE simply... does not execute parts of my code, and throws no exceptions.
    The sample code is a simple logging application, watered down to the bare minimum for the purposes of this forum:
    public class Log {
    public static void main(String[] args)    {Log log = new Log();}
    public Log() {Logger.log("Hello World");}
    import java.util.*;*
    import java.io.*;
    import java.text.SimpleDateFormat;
    public abstract class Logger {
    private static final int SIZE = 2;
    private static final SimpleDateFormat DAY = new SimpleDateFormat("EEEE");
    private static final String
      DIR = "logs/",
      EXT = ".log",
      FILTER = ".*log\\z",
      DNE = "DNE";
    private static int i,oldest;
    private static long previous = 0;
    private static FileFilter filter = new LogFilter();
    private static FileWriter out;
    private static File file,directory;
    private static File[] list;
    public synchronized static void log(String param) {
      try {
       directory = new File(DIR);
       file = new File(DIR + getDay() + EXT);
       list = directory.listFiles(filter);
       if (file.createNewFile()) {
        readOnly();
        reconcile();
       write(param);
      catch (Exception exception) {}
    private static void write(String param) throws Exception {
      out = new FileWriter(file, true);
      out.write(param);
      out.close();
    private static void readOnly() throws Exception {
      for (i=0;i<list.length;i++) {list.setReadOnly();}
    private static void reconcile() {
    try {
    previous = list[SIZE].lastModified();
    oldest = SIZE;
    for (i=SIZE;i<=0;i--) {
    if (list[i].lastModified() <= previous) {
    previous = list[i].lastModified();
    oldest = i;
    list[oldest].delete();
    catch (Exception exception) {System.out.println("Skipping reconciliation...");}
    private static String getDay() throws Exception {
    return DAY.format(Calendar.getInstance().getTime());
    private static class LogFilter implements FileFilter {
    public LogFilter() {}
    public boolean accept(File param) {
    try {
    if ((param.getName()).matches(FILTER)) {return true;}
    else {return false;}
    catch (Exception exception) {return false;}
    *The problem*:
    Ok, easy visual, this is the "log/" directory as I run the Log.java application repeatedly and iterate the date on my computer as I do so.
    Thursday
    *log/*
    +Thursday.log+
    Friday
    *log/*
    +Thursday.log+
    +Friday.log+
    Saturday
    *log/*
    +Thursday.log+
    +Friday.log+
    +Saturday.log+
    Sunday
    *log/*
    +Friday.log+
    +Saturday.log+
    +Sunday.log+
    Monday
    *log/*
    +Friday.log+
    +Saturday.log+
    +Monday.log+
    This is the point at which I go ???
    Turns out, the JRE skips the execution of my for loop in the *reconcile()* method when the date rolls over to Monday, and from then on it simply deletes the previous day's log instead of the oldest log.
    Why?  Who knows.
    Things I have tried:
    - Using another variable integer for the *readOnly()* method
    - Removing the synchronized keyword from the *log(String param)* method
    - Second call to *directory.listFiles(filter)* and setting *SIZE* to *3* after the old files have been set to read-only
    - Removing the call to *readOnly()*
    - Verified that the call to *readOnly()* does not alter the +modified+ date on the log files
    - Changed Logger.java from a +static+ class to a +local+ class
    Things I cannot do:
    This log application stores privy information about end-users at locations across the country in the event that there are support issues that need to be resolved, and the agreement is that we store this information no more than three days.  Just wanted to make sure, that the hopefully informed respondants to this issue, know that the obvious solution (storing seven day records), is unfortunately not available to me.
    Edited by: Threadstorm on Jan 8, 2009 8:24 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    HA! Most excellent. The last place I would ever look.
    Yes, seems like Java sorts the files in such a way that everything works fine without the loop until Monday rolls over.
    Now I can have a better appreciation for that second set of eyes.
    I use for loops so frequently that I never look at them (though I did stare at this one myself prior to this post, much to my chagrin now) but the subtracting iteration (which I use once in a blue moon) was necessary for the nature of the code.
    But ok, up and running! (whew) was going to be a long day until now.
    To answer your question though, the Logger is static so I don't have to pass it around to dozens and dozens of other modules but rather just include the package on the fly as I develop new modules that need to log information, and I like to write most mundane things myself if I can, that way I have the freedom to modify them at will.
    Thanks again! I'm now a happy camper once more.
    I'm also thankful that I don't have to chalk up another notch on the wall of cases where the JRE behaves magically and truly ignores code which I have definitely run into before. Something about listCellRenderers and the order of calls made to them, or some such and JRE doesn't read one of the lines. It's been a year or two.
    Edited by: Threadstorm on Jan 8, 2009 8:47 AM

  • Executing each step of a for loop only on a VISA read output

    Hi,
    I would like to give multiple steps to a motor/controller to exectue, but I keep getting a "command overflow" error.  Therefore, I am trying to tell the for loop only to execute when the VISA Read receives an output. I have included the .vi I have written so far. For example, the code /1P1000p66R tells the controller to move motor "1" forward 1000 steps and then to output the number "66" when the motor has moved 1000 steps. My input to the "table control" is, e.g., 3 commands:
    /1P1000p66R
    /1D1000p66R
    /1D5000p66R
    How do I get the code to send each of those commands only when the number "66" is sent back to the program so that I don't get the command overflow error? Also, if anyone has a better way to control the motor to do multiple steps, let me know. I'm pretty new to all of this. 
    Thanks.
    Attachments:
    Motor Controller (Sub VI 2).vi ‏26 KB

    Rather than using a table control, I would just use a string array.
    Set your serial port parameters before the loop.  Close the serial port after the loop.
    Your controls don't have any real data in them saved as default, so I'm confused a bit as to what your are trying to do.  Why do you have a numeric control with the number 0 establishing the loop iterations?
    Instead of a For Loop, use a while loop.  Set the 1-D array of strings to be autoindexing at the input tunnel.  Write the command (why you have everything wrapped in a case statement with a true constant makes no sense.  Do a VISA read.  If the response has the 66 (you'll have to figure out how to parse it out), all is good.  If it does not have the 66, or the number of loop iterations equals the number of commands in the array -1 , then end the loop.
    Message Edited by Ravens Fan on 05-20-2009 09:31 PM
    Attachments:
    MotorController(SubVI).vi ‏18 KB
    Motor%20Controller%20(Sub%20VI%202)[1]_BD.png ‏8 KB

Maybe you are looking for

  • How can I make my Time Machine backup copy-able again?

    Because one of my Time Machine hard drives failed catastrophically, I bought a replaceemnt disk and tried to copy the Backups from my second TM hard drive as a starting point for the new drive. The copy failed: "A075BE7D-541F-4AA8-80D6-E5E42DD9B198"c

  • Role Based FireFighter with GRC 10.0 (CEA)

    Does anyone know how the Role Based functionality of FireFighter exactly works besides putting the application type parameter to Role Based in SPRO? The manuals explain that the FF users log in to the remote system with their own users, but how are t

  • Bridge CS4 - Save/Print Photos from Web Gallery

    I have only been using Bridge CS4 for the last couple months to put web galleries on a web page.  I don't know how to change the settings to allow people to save/print the photos from the web gallery once it is posted on the website.  I used to creat

  • Combo Box inside dataGrid

    I have looked everywhere and I am having a hard time finding a good example of how to use a combo box in a datagrid. I want to use a dataprovider for my datagird but as soon as I get inside my itemRenderer it throws an error saying Access of undefine

  • CommPortIdentifier and JRE1.6

    Hi I have built an applet,signed all the jars it uses and when i print out a debug line in the CommPortIdentifier class, the part where it lists the available ports, it returns false. This leads me to believe that for some reason the CommPortIdentifi