Trouble Using TimerEvent in While Loop

Hello,
I am attempting to use a TimerEvent in a while loop. In the example I have created below, the init function should loop through the values myArray, tracing each value at three second intervals. It seems, however, that because I am incrementing the currentNum value outside of the while loop (in the timerHandler function), that the loop just keeps running until Flash stops responding.
var myArray:Array = new Array("one", "two", "three", "four", "five");
var currentNum:int;
var myTimer = new Timer(3000, 1);
function init():void {
while ( currentNum < myArray.length ) {
trace(myArray[currentNum]);
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, timerHandler);
    myTimer.start();
function timerHandler(e:TimerEvent):void {
currentNum += 1;
init();
I am wondering if what I am trying to do is simply not possible or if I am missing something.
Thanks in advance for any thoughts on the matter.

Thanks, Ned. That makes sense. I was able to work around my problem by getting rid of the while loop and using a conditional statement to test if I had reached the end of the array.
var myArray:Array = new Array("one", "two", "three", "four", "five");
var currentNum:int;
var myTimer = new Timer(3000, 1);
function init():void {
traceArrayValue();
function traceArrayValue():void {
trace(myArray[currentNum]);
if (currentNum + 1 < myArray.length) {
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, timerHandler);
    myTimer.start();
function timerHandler(e:TimerEvent):void {
currentNum += 1;
traceArrayValue();
init();

Similar Messages

  • I am using a timed while loop and am unable to get the loop to run at a speed of less than 1ms (I am currently using the Wait(ms) function). How can I get a faster response?

    I am trying to create a virtual engine within a timed while loop and am unable to get the loop to run at a speed of less than 1ms (I am currently using the Wait(ms) function). This does not however allow realistic engine speeds. How can I overcome this? I have access to a PCI-MIO-16E-4 board.

    andyt writes:
    > I am using a timed while loop and am unable to get the loop to run at
    > a speed of less than 1ms (I am currently using the Wait(ms) function).
    > How can I get a faster response?
    >
    > I am trying to create a virtual engine within a timed while loop and
    > am unable to get the loop to run at a speed of less than 1ms (I am
    > currently using the Wait(ms) function). This does not however allow
    > realistic engine speeds. How can I overcome this? I have access to
    > a PCI-MIO-16E-4 board.
    Andy,
    Unless you use a real time platform, getting extactly 1 ms loop rate
    (or even less) is impossible. It starts getting troublesome at about
    0.1 Hz for standard operating systems.
    I'd tackle your problem with "if i mod 10 == 0 then sleep 1 ms".
    Of
    course this is jerky by design.
    HTH,
    Johannes Nie?

  • How do I create an xy chart using two independent while loops?

    Hi everyone,
    I am trying to develop a data acquisition program. In this program, I have two independent while loops that each output a number of type double each iteration of the loop. I am able to successfully create two independent waveform charts (data vs. time) for each of the loops when it is placed inside. However, I now want to create an xy chart of the live data (the output of one loop is x and the output of the other is y).
    I am having trouble doing this because of the separate nature of the loops...when I try to pull data outside of the loops it (naturally) doesn't refresh with each loop iteration causing the xy chart to not work in the way I intend. Is there an easy way to fix this? If more clarification is needed, please let me know!
    David
    Solved!
    Go to Solution.

    Yes, more clarification is needed. Please attach your code to clarify.
    I'll take a wag at it, though. It sounds like you are trying to pair X and Y data which happen during a single time chunk, then repeat, is this right? (If not, don't bother to read on.) If so, why not just use a single loop. If your VI is getting too big/complicated for comfort, just put the data-generating stuff into subVIs which run to generate a single data point, then stop, put them into a while loop and send the putputs to a graph or chart inside the loop. That way you won't extend your data trace until you get one and only one point from each subVI and things will stay synchronized.
    Cameron
    To err is human, but to really foul it up requires a computer.
    The optimist believes we are in the best of all possible worlds - the pessimist fears this is true.
    Profanity is the one language all programmers know best.
    An expert is someone who has made all the possible mistakes.
    To learn something about LabVIEW at no extra cost, work the online LabVIEW tutorial(s):
    LabVIEW Unit 1 - Getting Started
    Learn to Use LabVIEW with MyDAQ

  • Implications of using a while loop for a wait.

    Hi,
    I need to make a thread wait until a condition is met before it can continue. I am currently using:
    while(locked){
          //Wait
    }What would be a better way of doing this as i need to keep the CPU usage as low as possible.
    Thanks for any help.

    Yes, thanks for the link. I am reading it now.
    Its not too easy becasue i am not writing pure java classes.... (Hard to explain) I dont have access to all threads.
    While im reading this could you re-asure me that im thinking about this in the right way (or not).
    I have one thread that executes some stuff then sets a global variable to true (locked = true). This thread then needs to wait until the global variable is set back to false (by another thread).
    Another thread does some processing and then sets the global variable to false (locked = false) meaning that the original thread can carry on.
    At the moment i am using the above while loop to wait but im sure there is a better way of doing this.
    Thanks

  • Help learning while/do while loops

    Hi everyone, glad to see there are resources out here like this where newbies with Java can get help and learn from the gurues!
    I am having a problem with constructing a while loop that is going to compute the sinx without using the Math.sin function....so given this
    sinx = x - (x^3/3!) + (x^5/5!) - (x^7/7!) + ......
    It seems I need to use the Math.pow function. So the sinx is alternating signs between each new set of parenthesis and the power and factorial are increasing by 2..starting with 3. I think this is were I am having my trouble.
    I was going to use a do-while loop for cosx which is
    cosx = x - (x^2/2!) + (x^4/4!) - (x^6/6!) + ......
    I think my problem is that I can't figure out how I would go about writing this. If I can get the sinx with the while loop, I can probably get the cos on a do-while statement since they are similar. I did get factorial(n) defined below.
    I have another main class which I am using to get the input of sin/cos x using computeSin and computeCos functions I am trying to build here.
    import javax.swing.*;
    public class NewMath
    public static double computeSin(double x)
    double result = x;
              // Going to use A WHILE LOOP
    return result;
         public static double computeCos(double x)
    double result = 1;
              // Going to use a DO-WHILE loop
    return result;
    private double factorial(int x) {
    if (x <= 1) return 1.0;
    else return x * factorial(x - 1);
    Any tibits of help would be nice. If I think I got it working before someone else posts, I'll post my results. Thanks.

    Any tibits of help would be nice. If I think I got
    it working before someone else posts, I'll post my
    results. Thanks.You already have your own tidbits, as you've observed the pattern of alternating adding/subtracting, as well as how the power and factorial factors relate. Any more "tidbits" here would just result in doing it for you, it seems. So get to it, and if you run into specific problems, you can ask.

  • What is the best way   for writing cursors in while loops

    i just chage my flatform from visual foxpro to sql
    for every report part using query analyser i have to make report on any tables
    suppose : - mastempno wise report
    so i heve to use cursor or store procedure in while loop
    for searching in transaction table
    so sometime i get confunsion of using cursors two times in while loop for fetching the values
    so help me for writing some simple codes for using cusrors in while loop while can fetch all values in transaction table

    Is this what u r looking for
    A Simple Cursor Example Which gives all records
    from Employee table
    Declare
    Cursor Emp is
    Select Empno,Ename
    FRom Employee;
    Begin
    For x in Emp Loop
    :block.empname := x.ename;
    End Loop;
    End;
    Regards,
    Ashutosh

  • Empty while-loop taking too much power

    Hi all!
    Would someone help me out with a better implementation of the below code. 'guard' is a class handling validation of users againt a database. I'm waiting for it to finish in an empty while loop in my GUI-class (extending JFrame). This obviously takes all CPU causing bad response time. Any smart suggestion on how to reduce this in my case?
    Thanks in advance.
    //Wait for the guard to validate user
    while(guard.getGrantedPermission() == guard.PENDING) {}
    if(guard.getGrantedPermission() == guard.ACCESS_ALLOWED) {
        setVisible(true);
    * We should be able to work with the config object since it should
    * be initialized when the password dialog prompts the user
       try {
          user = guard.getValidatedUsername();
          //Set the name of the customer
          config = new Config(user, new Date());
       } catch(NullPointerException npe) {
          npe.printStackTrace();
    }

    Don't use an empty while loop. It's a terrible construct. Listen to zurdo (the first reply). Don't use Thread.sleep() either, as it's inappropriate in your case.
    If you don't want to use Observer and Observable, then use a new Thread using the wait() and notifyAll() constructs. See the tutorial at
    http://java.sun.com/docs/books/tutorial/essential/threads/index.html
    Pay careful attention to its warnings, though.

  • Unxepected behaviour with clusters inside of while loop with shift register

    Colleagues,
    I just would like to post here small, but important bug (I guess this is the bug), which was found by coworker today morning. Just would like to share knowledge, and probably this will save some debugging time for you...
    So, the problem that you can get wrong content of the cluster in some cases. The cluster used inside of while loop with shift register (we using this construction for functional globals), and after bundle operation you can get data, which are not expected:
    See also attached code for details (LabVIEW 8.6.1, WinXP Prof SP3).
    best regards,
    Andrey.
    PS
    Bug report already sent to NI.
    Message Edited by Andrey Dmitriev on 10-16-2008 12:30 PM
    Attachments:
    BugwithClusters.png ‏15 KB
    BugwithClusters.zip ‏10 KB

    Thanks Andrey for brining this to our attention!
    The "Show Buffer Allocations" reveals that LV is not processing the code in the right order.
    Under ideal conditions, all of the data should be manipulated using the buffer "A". But as this demo shows the data is being processed in the wrong order.
    The previously posted workaround get around this by forcing the array operation to happen first, but this resluts in two additional buffers "C" and "D" and then copy this back into "B".
    Using an "Always Copy" is another workaround that uses a seperate buffer "F" to hold the data being moved from the first cluster to the second inside "E".
    I think you won a shinny new CAR* Andrey!
    Ben
    CAR = Corrective Action Report
    Message Edited by Ben on 10-16-2008 08:05 AM
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction
    Attachments:
    Cluster_Bug.PNG ‏57 KB

  • Cursor without WHILE loop

    I have always seen and used CURSORs with WHILE loops.
    I am looking for great examples where CURSORs are used without WHILE loops. Thanks.
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Database Design
    New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014

    You can implement any logic that you want. We need to know what is your needs in order to post a code. If all you need is to make a loop on all the SET in the same way while do, without using while loop then here is a simple example. You can implement any
    WHILE loop with IF condition and GOTO. This is only for sake of discussion and I will not use this code in production :-) 
    use AdventureWorks2014
    GO
    SET NOCOUNT ON;
    DECLARE @vendor_name nvarchar(50)
    DECLARE vendor_cursor CURSOR SCROLL FOR
    SELECT Name
    FROM Purchasing.Vendor
    WHERE PreferredVendorStatus = 1
    OPEN vendor_cursor
    PRINT '******** Using While loop ********'
    FETCH NEXT FROM vendor_cursor INTO @vendor_name
    WHILE @@FETCH_STATUS = 0
    BEGIN
    PRINT @vendor_name
    FETCH NEXT FROM vendor_cursor INTO @vendor_name
    END
    CLOSE vendor_cursor;
    OPEN vendor_cursor
    PRINT '******** Without Using While loop! ********'
    FETCH NEXT FROM vendor_cursor INTO @vendor_name
    Starting_Read_From_Cursor:
    -- Using If with GO TO
    IF @@FETCH_STATUS = 0 BEGIN
    PRINT @vendor_name
    FETCH NEXT FROM vendor_cursor INTO @vendor_name
    GOTO Starting_Read_From_Cursor
    END
    CLOSE vendor_cursor;
    DEALLOCATE vendor_cursor;
    I hope this useful :-)
    I am not sure for what, at the moment
    [Personal Site]  [Blog]  [Facebook]

  • While looping

    Hi friends,
    my requirement is
    while looping..
    if the invoice no is same
    then it should add the  box No's.
    can any one help me.
    pls send the sample code.

    add it to what? To internal table.
    Try and use field-symbols while looping and than say <line>-box_no = 1234.
    Internal table will automatically be updated.

  • How to use one single boolean button to control a multiple while loops?

    I've posted the attached file and you will see that it doesn't let me use local variable for stop button, but I need to stop all the action whenever I want but more than one single button on the front panel would look ugly... The file represents the Numeric Mode of
    HP 5371A. thanks for your time
    Attachments:
    NUMERIC.vi ‏580 KB

    In order to use a local variable, you can change the mechanical action of stop button (Switch When Pressed will work), or create a property node for it and select values. You'll also have to do a lot of work changing those for loops into while loops so that you can abort them.

  • Sir i am using datasocket read ,i am communicating with java but my problem is that bcz im using while loop to see if value has changed my labview consumes all the processors time ,sir i want a event like thing so that while loop is not in continuous loop

    sir i have given lot of effort but i am not able to solve my problem either with notifiers or with occurence fn,probably i do not know how to use these synchronisation tools.

    sir i am using datasocket read ,i am communicating with java but my problem is that bcz im using while loop to see if value has changed my labview consumes all the processors time ,sir i want a event like thing so that while loop is not in continuous loopHi Sam,
    I want to pass along a couple of tips that will get you more and better response on this list.
    1) There is an un-written rule that says more "stars" is better than just one star. Giving a one star rating will probably eliminate that responder from individuals that are willing to anser your question.
    2) If someone gives you an answer that meets your needs, reply to that answer and say that it worked.
    3) If someone suggests that you look at an example, DO IT! LV comes with a wonderful set of examples that demonstate almost all of the core functionality of LV. Familiarity with all of the LV examples will get you through about 80% of the Certified LabVIEW Developer exam.
    4) If you have a question first search the examples for something tha
    t may help you. If you can not find an example that is exactly what you want, find one that is close and post a question along the lines of "I want to do something similar to example X, how can I modify it to do Y".
    5) Some of the greatest LabVIEW minds offer there services and advice for free on this exchange. If you treat them good, they can get you through almost every challenge that can be encountered in LV.
    6) If English is not your native language, post your question in the language you favor. There is probably someone around that can help. "We're big, we're bad, we're international!"
    Trying to help,
    Welcome to the forum!
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • Using while loops instead of for loops in arrays?

    I am new to java and doing a java tutorial on using arrays and for loops. What im trying to find out is how it is possible to use a while loop instead.
    I would be very grateful if anyone can suggest a way of changing my code to use a while loop.
    The code I have written is:
    public class DetermineGrade
    public static void main(String[]args)
    final char[] mark = {'A','B' ,'C' ,'D' ,'F' };
    char [] grade = new char[5];
    int [] Score ={95,35,65,75};
    for (int i=0; i<4; i++)
    if (Score >= 90)
    grade= mark[0] ;
    else if (Score >=80)
    grade = mark[1] ;
    else if (Score >=70)
    grade = mark[2] ;
    else if (Score >=60)
    grade = mark[3];
    else grade = mark[4];
    for (int i=0; i<4; i++)
    System.out.println("grade = " + Score + ", " + grade);
    Thankyou LB

    Im trying to underdstand the differences in the
    different loops. I can grasp the for loop but I dont
    see how a while loop works, or how it id different
    from the other?
    for (j = INIT; j < MAX; j++) {
        // do stuff
    }is the same as
    j = INIT;
    while (j < MAX) {
        // do stuff
        j++;
    }Lee

  • How should I set up my VI so that I can use the linear fit coefficient data analysis program, when my values are coming from while loops within a sequence structure?

    I'm attempting to create a calibration program, using the printer port, and a Vernier Serial Box by modifying a calibration program designed for the serial box.
    There are six calibration points, and to collect them, I have it controlled by while loops so that the numbers are taken when a button is pushed, and this is inside a sequence structure so that I can get the six different points. I feed these numbers into two different arrays (for x and y values) and then try to use the linear coefficient analysis on these points, but the values for the slope and intercepts it returns are not correc
    t.
    If I cut out the array and coefficient analysis, and feed the same numbers in directly without the while loop and sequence structures, it produces the proper values... I don't know why the numbers it is producing are different, and I'd really like to know.
    Thanks,
    Karinne.

    I would use a data manager sub-vi that would be called by each from of the sequence structure that produced a data point. The data manager sub-vi could auto append new items or could place items in a specific entry of an array. Later on when you want to calculate the linear fit, call the sub-vi to return the array of values.
    Stu

  • How do you plot multiple curves on the same graph when using a while loop?

    I am writing a program that will plot the IV Output chracterisitcs curves for a MOSFET transistor. I have two sweep variables Vg and Vd. For each Vg valve selected, Vd is swept from its start to stop voltage creating a graph for that Vg valve. Both of the sweeps are done using while loops. Ideally I would like to display all of the Vg plots on the same graph while having the ability to do real-time graphing. Can anyone help me figure this problem out? I have attached my program. Thanks!!
    Tammy
    Attachments:
    outputfin2.vi ‏165 KB

    Hi Tammy & Tica T,
    As far as I see it - this thread is a very bad version of already existing bad version......
    http://forums.ni.com/ni/board/message?board.id=170&message.id=127857
    I expected, that an Applications Engineer from NI knows something about  a Transistor and how an Output characteristic looks like !!  Take a look to a typical Transistor Datasheet ( e.g. n-channel MOSFET) - you will see, that there is no relation of ID vs Time like in your example ( values vs time )  but  IDrain vs VDrain at different VGate's ( no relation to Mr. Bill Gates ).
    Find attached a vi, that in general does what you need - drawing of  curves vs x-axis (XY-graph in use)  - in test_sweep.zip.  And that you geet an impression, how it might be done ...... dynamic Output characteristic of a Transistor with Standard Equipment of a Lab ( Scope + Generator + Power Supply ) find in addition a Frontpanel - picture. One of the interesting points here is - the self-heating effect; visible on ch3 of scope - 5µs Pulse is already a very long time...... This measurement was done in order to compare with our own Transistors......... 
    Hope this helps a little bit to understand, what we are talking about.
    Regards
    Werner
    Attachments:
    test_sweep.zip ‏358 KB
    dynamic Transistor char.png ‏65 KB

Maybe you are looking for

  • How do I stop iCal from sending notifications everytime I change a shared calendar or event?

    iCal sends a notification (not an email) to all users of a shared calendar whenever an event is added or edited. How do I stop that?

  • SQL Query in mapping to load warehouse table

    Hi experts, I hope you can help me to solve my problem. I already searched here in forum how we can add a query in a mapping but still not found an answer. In my warehouse I have a time dimension table which has a unique dimension key and all date in

  • Mac App Store app does not install. How do I get a refund?

    I purchased an app from the Mac App Store (Connect360 - $20).  I "installed" the app from the Mac App Store.  The app appears on the dock and loads, but when it's done, it disappears from the dock.  The app is not located in the Applicaitons menu lik

  • Can't install software on my Mac OS X 10.9.4

    Hello everyone, I seem to have a problem installing new software... For some reason I can't install anything, the installer opens and I follow every step, but in the installation step, the bar just keeps moving but never actually moves as in completi

  • Confirmation issue

    Dear Experts, Can anybody help me out in this.. For an order type we have auto GI and auto GR at the time of confirmation. The task for me was to restrict the Exceeding of confirmation qty than the order qty.. I have done that by OPk4, over delivery