Prevent overwriting of variable during second loop...

Hello together, I have an issue with getting the first
value of a variable -
I want to store the value of an output variable in the first
sequence of my for loop.
How can I prevent that the variable is not being overwritten
during the next loops.
Would appreciate some hints thanks...

The first call does what it says : true on the first call, false on the rest of the time. Can't be used if your loop is called several times.
You could simply use a case structure, connected to the loop index and detecting the i = 0 case, as in the attached example.
Chilly Charly    (aka CC)
         E-List Master - Kudos glutton - Press the yellow button on the left...        
Attachments:
Store first result.vi ‏14 KB

Similar Messages

  • Problem using local variable in event loop

    I have a state machine from which I want to monitor various controls, including "Start" and "Stop" buttons.  Not every state needs to monitor the controls.  At present, most states run timed loops.  In the first state that reads the front panel, I have an Event structure (inside a While loop) that monitors the various controls' Change Value events.  For numeric controls, I update variables (in shift registers) as needed.  The "Start" button is used to end the While loop controlling the Event structure, allowing the State to exit to the next state.
    My problem comes in subsequent states that employ this same idea.  Here, I put a Local Variable bound to the Start button and use the same code, but it frequently happens that when I enter this particular state, I cannot "turn on" the control -- I push the button, but it stays off.  Curiously, if it was On when I enter, I can turn it off, but then I'm stuck not being able to turn it on.
    I mocked up a very simply routine that illustrates this.  There are two sequences (corresponding to the two states).  Both use an Event loop with a local variable bound to my Stop button (really this is an LED control with custom colors).  I've deliberately moved the "initialization" (the declaration of the control in the block diagram) out of the Event loops -- putting it inside the first loop modifies the behavior in another strange way.
    Here's my thinking on how I would expect this to work:  The code outside Event Loop 1 should have little effect.  Assume the Stop button is initially Off.  You will "sit" in Event Loop 1 until you push the Stop button, changing its value to True; this value will be passed out of the Event case and cause the first While loop to exit.  You now enter the second sequence.  As I understand the Exit tunnel, it defaults to "False", so I'd expect to stay in the second Event loop until I turn the Stop button from On to Off, which will pass out a False, and keep me in the While for one more button push.  However, this doesn't happen -- I immediately exit, as though the "True" value of the Stop local variable is being seen and recognized by the Event loop (even though it hasn't changed, at least not in the context of this second loop).
    An even more curious thing occurs if I start this routine with the Stop button turned on.  Now I start in my Event loop waiting for a change, but this time the change will be from On to Off, which won't cause an exit from the frame.  This will be reflected by having the While loop count increment.  We should now be in the state of the example above, i.e. in an Event loop waiting for the control to be pushed again, and turned On.  However, clicking the control has no effect -- I cannot get it to "turn on".
    Where am I going astray in my thinking?  What is it about this method of doing things that violates the Labview paradigm?  As far as I can tell, what I'm doing is "legal", and I don't see the flaw in my reasoning, above (of course not -- otherwise I'd have fixed it myself!).  Note that because I'm using local variables inside Event loops (and I'm doing this because there are two places in my code where I want to do such testing), the Stop control is not latching (as required).  Is there something that gets triggered/set when one reads a latched control?  Do I need to do this "manually" using my local variable?
    I'll try to attach the simple VI that illustrates this behavior.
    Bob Schor
    Attachments:
    Simple Stop Conundrum.vi ‏14 KB

    altenbach wrote:
    Ravens Fan wrote:
    NEVER have multiple event structures that share the same events. 
    Actually, that's OK.  NOT OK is having multiple event structures in the same sequence structure.
    See also: http://forums.ni.com/ni/board/message?board.id=170&message.id=278981#M278981
    That's interesting.  I had always thought I read more messages discouraging such a thing rather than saying it was okay.  Your link lead me to another thread with this message. http://forums.ni.com/ni/board/message?board.id=170&message.id=245793#M245793.  Now that thread was mainly concentrating on registered user events which would be a different, but related animal. 
    So if you have 2 event structures they each have their own event queue?  So if you have a common event, one structure pulls it off its event queue and it does not affect the other structure's event queue?  I guess the inherent problem with this particular VI was that the second event structure locked the front panel.  Since the code never got to that 2nd event structure because the  first loop never stopped because the change was from true to false.  After reading your post and the others, I did some experimentation and turned off the Lock front panel on the 2nd structure, and that prevented the lockup of the program.
    Overall, the example VI still shows problems with the architecture and I think your answer should put the original poster on the right track.  I think as a rule I would probably never put the same event in multiple structures, I feel there are better ways to communicate the same event between different parts of a program,  but I learned something by reading your reply and about how the event structures work in the background.  Thanks.

  • Add values to one variable in a loop

    Hello,
    I have a while loop where I read a counter and get values.
    Now I want to add all values to one variable. I think an array won't be good because
    the loop can run a long time and an array is limited.
    And the end I want to have the sum of all values.
    I tried to use shift registers.
    But how can I store the value of the first loop-cycle in a variable and on
    the second loop-cycle take this stored value and add the new value and so on?
    Another problem that is maybe more difficult, is that I need the max and min value
    of all values that has been read.
    That means I need a variable which stores the current value. Then I have to compare the stored
    with the next value and maybe exchange both.
    I would be thankful fo
    r any hints.
    best regards Thomas

    Attached is a picture of a code that does what you want; it calculates the sum of each value, it finds the minimum and maximum (and average)...and it does not create any arrays.
    The value source and the condition to stop the loop is what you need to change...In addition you might want to see preliminary values...if so then add indicators inside the loop.
    MTO
    Attachments:
    sum_min_max.gif ‏27 KB

  • SmartForms - Window position variable during runtime?

    Hello,
    is it possible to create one window in smartforms and set
    during runtime the position variable?
    Otherwise i have to create around 70 little windows
    The backround is: i create during a loop for each dataset a 2D-Barcodes. In our SAP system we create 2D-Barcodes like that:
    - the Title of a window must start with LS_BARCODE....
    - then in Lasersoft (thats a "printing"-software between SAP and the printer) this software reads this title LS_BARCODE and creates an 2D Barcode with the datas in the textfield below the window.
    best regards,
    jasmin

    Hello Jasmin,
    Perhaps note 359009 will address your problem or provide you with a workaround, using the "late processing" type window.
    Kind Regards,
    Martin

  • Script sub-routine crashes on second loop

    G'day
    I've got a 2000+ line Mail script that worked in Tiger, but seems to be a problem under leopard.
    The first pass getting a Mail message ID works ok, but on the second pass, when getting a new ID, as soon as I try and use the ID variable, the script shows the ID once, then completely stops.
    I've written a short version of the script to demonstrate the dilemma, but its still over 65,000 characters.
    I can send the whole script to anyone kind enough to try it. Mail me at [email protected]
    Anyone kind enough to run it must
    1. first create a mail folder called "* items to shift"
    2. Alter the short piece of script after the 'Set to suit' comment, to set your printer and email address.
    3. Then the script must be saved in the main Library/Scrips/Folder Action Scripts.
    4. Then, the script must be attached as a Folder Action to the 'messages' folder INSIDE the actual "* items to shift.mbox" mail folder which is in.....
    <your home folder>/Library/Mail/Mailboxes.
    5. Enable 'Access for Assistive devices' in the 'Universal Access' control panel.
    Now, drop some mail on the '* items to shift' mail box. The second message should freeze after showing the ID once. The mail won't disappear, but will be shifted to a newly created dated mail folder.
    The piece of offending script is as follows...
    on MainLoopTwo(this_folder)
    tell application "Mail"
    activate
    repeat while (number of messages of mailbox MailBoxName) > 0
    set frontmost of application "Mail" to true
    if RunForOz then say "main loop"
    set EveryMailboxList to mailboxes
    repeat with testBoxName in EveryMailboxList
    set selected mailboxes of message viewers to {mailbox MailBoxName}
    if (name of testBoxName as string) ≠ MailBoxName then
    set selected mailboxes of message viewers to {mailbox (name of testBoxName as string)}
    exit repeat
    end if
    end repeat
    set CycleThroughMessages to last message of mailbox MailBoxName
    tell application "Mail"
    activate
    set TheName to ""
    set TheName to the (id of CycleThroughMessages & ".emlx" as string)
    set frontmost of application "Mail" to true
    try
    if (exists CycleThroughMessages) in mailbox MailBoxName then
    if my CheckThePausedReference(TheName) then
    set byPassPrint to true
    my TransferToITMP(CycleThroughMessages, true)
    end if
    else
    set byPassPrint to true
    end if
    on error TheError number errNum
    say "oooooops, can't set i d"
    set TheName to ""
    set byPassPrint to true
    end try
    set thetempname to TheName as string
    tell application "System Events"
    try
    tell application "Mail" to display dialog thetempname
    -- Next line after second loop fails after previous line.
    -- 'On Error' does not trap error
    -- Script simply stops
    tell application "Mail" to display dialog thetempname
    on error
    say "error"
    end try
    end tell
    if RunForOz then say "main loop continues"
    my MainLoopThree(CycleThroughMessages)
    end tell
    end repeat
    end tell
    set TimeToElapse to my seeiftimehaselapsed("Check if elapsed")
    if TimeToElapse = "" then -- No time stored, so check if to recycle
    say "Checking recycle"
    tell application "Mail"
    set TemporaryMail2 to messages of mailbox MailBoxName
    end tell
    if (count of TemporaryMail2) > 0 then my MainLoopTwo(this_folder)
    end if
    end MainLoopTwo

    G'day
    For your information.
    I've worked out what the problem is.
    After removing a message from a series of messages in a mailbox, using a repeat loop or any other way, after about 5-10 seconds the Mail App seems to send an update signal to itself, or to Applescript, I'm not sure which.
    This update causes any dialog box, or open message, to very briefly 'flicker'. Once that happens, the script can't run anything else.
    The workaround is to run the main script on it's own, and call it from a short folder attached script.
    The problem only arises when the script is directly attached as a folder action, and in Leopard.
    A definite bug I think.
    Regards
    Santa

  • Using variables in a loop

    Hello and thanks in advance!  I'm attempting to insert records into a temp table using a loop.  I have many declared variables that will be used as criteria in the query.  Since the variable are all named the same other than a ascending
    numberic to the name, how would I get a variable in a loop to substitute the "numberic" part of the variables? I've created some sudo sql for what I'm trying to achieve:
    Declare @Start1 as Date = '2014-01-01'
    Declare @Start2 as Date = '2014-15-01'
    Declare @Start3 as Date = '2014-18-01'
    Declare @i INT = 1
    WHILE @i < 20
         SELECT .... INTO #MyTemp ...
         WHERE OrderDate Like @Start + @i       --This is the line I cant seem to get working.
         SET @i = @i +1
    END

    >>You have just described a 1950's file system using punch cards (also called unit records) writing to a scratch tape with Autocoder. You have no idea how to write SQL or program in a declarative language. We do not sure temporary files or loops. The
    goal is to write one statement that does the task. We do not use local variables; we use expressions that compute their values.<<
    What are you talking about or your point? I dont ever remember asking about temporary files. Who is the 'We' you keep referring to?  why did you even bother posting with a negative and absolutely unhelpful reponse.
    >>That is called an “array” in procedural programming and a repeated group in RDBMS. It also violated First Normal Form (1NF). <<
    Wrong. I said that I created variables.  I did not say I created an array.  Also, you have no idea of what I was trying to accomplish. 
    >>
    If you truly do not care about ever being a good programmer, you can kludge this 1950's code with dynamic SQL. But I will use you as a bad example in my books :(  <<
    I have no idea who you are and take offense at your entire post attempting to tear me down.  Your arrogance and attitude appears to have grown with your forum points.  I'm still confused as to why somebody with your so-called expertise
    posted such an a$$#*%! comment.

  • Preparing clip for website, show first 5 seconds, loop the next 5

    I'm working on a title...
    I would like the first 5 seconds to only show when a webpage is loaded, for simplification, we'll just say this is for QuickTime instead of a website.
    The whole thing: animated background texture, animated texture on the text
    The beginning: text appears using some effects, has the mentioned animated texture
    The end: the background texture continues to animate, as well as the animated texture on the text
    Only difference between beginning and end: the text does not need to appear, it only needs to show once when the video is played.
    In summary:
    Is it possible to have the first 5 seconds play once, and the next 5 seconds loop continuously? How?
    Thanks a million!

    Is it possible to have the first 5 seconds play once, and the next 5 seconds loop continuously? How?< </div>
    Not in Livetype, no. all you do in LT is create the content. How it is played out or displayed is controlled in your streaming controller.
    bogiesan

  • Get value of formula variable during query runtime into a text variable

    Hi all,
    I wanna get the value of the formula variables during the query runtime into a text variable.
    My scenario is like this: First I defined a formula variable Z_DATE_3 which is processing by replacement. It will get the day of a characteristcs(Startdate).
    Then I defined a text variable and in the function module related to this text variable, I used the parameter I_T_VAR_RANGE which can store the value of formula variable during the query runtime.So I can read the value from this table in my function module.
    But I have a issue, when I run the query which used the defined text variable, it seems that it doesn't call the corresponding function module. Because I set a breadpoint in hte code and it never reach this breakpoint.
    If I removed the parameter I_T_VAR_RANGE , it can enter the function module.
    So could you please give some advice?
    Is my solution correct or not?
    And what's wrong with the parameter I_T_VAR_RANGE? Did I use it correctly?
    And My code is:
    DATA:  l_s_range_v TYPE rrrangeexit,
                 l_day type sy-datum.
    if i_step <> 2.
    raise no_processing.
    endif.
      READ TABLE i_t_var_range INTO l_s_range_v
         WITH KEY  vnam = 'Z_DATE_3'.
    if sy-subrc = 0.
         l_day = l_s_range_v-low.
    endif.
    Thanks in advance!
    Best regards
    Fanchest

    Hi, Fanchest,
    I'm having just the same issue.  Did you find a solution?
    I wrote a short routine in CMOD to derive the value of a formula variable to a text variable, but it's not working (I don't get any value).  Can you share your solution?
    Thanks in advance,
    LL

  • HT4236 (PC) When I sync a folder of photos, they sync to the generic photo library on my iPhone, but it creates another folder with duplicates of the pictures. How do I prevent/get rid of this second folder?

    (PC) When I sync a folder of photos, they sync to the generic photo library on my iPhone, but it creates another folder with duplicates of the pictures. How do I prevent/get rid of this second folder?

    Um... that does not contain "duplicates".
    It's just a view that shows you everything that's in your other albums and events in one place...

  • Prevent overwrite of upload file

    I'm using jspsmart to upload file to the server.
    How can I prevent overwrite of file ?
    for example,
    User A have a file call "abc.txt" in the server. Now, another user B upload a file call "abc.txt".
    The problem is User A and User B upload the file with the same filename in the same directory.
    Any method can give User B a warning signal to prevent overwrite of the file.
    Thank you !

    To prevent an overwrite of a file, first check to see if file exists BEFORE uploading the file.
    For example.
    String filename = "abc.txt";
    File f = new File(filename);
    if(f.exists()) // file already exists ->give error
    else // file not exists->upload file

  • Unable to click on buttons during timed loop .

    Hi !
    I have a timed loop with a cadence set by user . And when the loop is running, I can not push any button of my GUI to stop this....
     I have to wait until error or I stop the run.
    I can't put the diagram it's too big and I think I haven't the right but do you have some ideas ?
    Ask me for more details .
    Thanks
    Solved!
    Go to Solution.

    bejard wrote:  The Timed loop is just in an event structure and I set 10 ms or 100 ms .
    The program is running correctly (with this Timed loop of 10ms/100 ms) as the beginning but I still can't push any button or change tabs during the loop .
    You should not have long processes inside of an event case.  What is supposed to stop your timed loop?
    I think you have the "Lock front panel until event case completes" option turned on.  This will not allow you to press anything until everything in  that event case (including the timed loop) completes.
    In my experience, using a timed loop in a Windows system is a complete waste and often adds more overhead and issues.  Instead, I really think you need to change over to use a State Machine.  When the button is pressed, you just tell your state machine to go into the state the runs some of the code inside of your timed loop.  You can use the state with the event structure to time your loop.  So you can go back and forth from your event structure state to your processing loop.  Just set the timeout on the event structure to whatever loop rate you actually want.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Assigning value to array type variable in a loop

    Hi
    I have a scenario in which i am assigning value from a array type variable(x) to the invoke variable of a database adapter. The variable x is exact replica of the invoke variable.
    My copy operation in assign activity looks like this-
    <copy>
    <from variable="Var" part="InputParameters"
    query="/ns7:InputParameters"/>
    <to variable="Invoke_call_XXDPI_EDI_852_PKG_InputVariable"
    part="InputParameters"
    query="/ns7:InputParameters *(* bpws:getVariableData('iterator') *)* "/>
    </copy>
    It is inside a while loop activity.
    PS *()* are square brackets
    But it is erroring out at run time.
    Does anybody has an alternate idea to assign value to an array type?.
    i have seen that while extracting value from an array type variable it works fine
    A similar kind of operation is shown below.
    <copy>
    <from variable="Var" part="InputParameters"
    query="/ns7:InputParameters *(* bpws:getVariableData('iterator') *)* "/>
    <to variable="Invoke_call_XXDPI_EDI_852_PKG_InputVariable"
    part="InputParameters"
    query="/ns7:InputParameters"/>
    </copy>
    Thanks
    Ayush
    Edited by: Ayush fujitsu on Aug 14, 2009 4:36 AM

    Hi Ayush
    I suppose you are getting some error like "source node returns multiple elements".
    In second case there is no problem because you are assigning *InputParameters[bpws:getVariableData('iterator')]* (+suppose InputParameters[1]+) to target. Here it works fine because you are fetching oonly 1 value from source and assigning it to the target.
    Now in first case you are saying copy InputParameters to target[1] suppose. You know that source is an array which contains multiple index so which index field from the source will be assigned to the target.
    Try your process with only 1 source value it will work but when multiple values will be there it will fail. You have to merge both the cases and it will look like
    *<copy>*
    *<from variable="Var" part="InputParameters"*
    query="/ns7:InputParameters ( bpws:getVariableData('iterator') ) "/>
    *<to variable="Invoke_call_XXDPI_EDI_852_PKG_InputVariable"*
    part="InputParameters"
    query="/ns7:InputParameters ( bpws:getVariableData('iterator') ) "/>
    *</copy>*
    And the easiest way to do this is by the transform activity as said above.
    Regards
    Suryaveer
    Edited by: Suryaveer on Aug 15, 2009 11:19 PM

  • Using variables in if loop

    Hi,
    I have created 2 updatable variables BizDaysOld & BizMonth. I need to update BizDaysOld based on the values of these variables. I am using the following if statement. It doesnt work.
    <?xdofx:if (xdoxslt:get_variable($_XDOCTX, 'BizDaysOld')) > 0 and (xdoxslt:get_variable($_XDOCTX, 'BizMonth'))=9 then
    xdoxslt:set_variable($_XDOCTX, 'BizDaysOld', xdoxslt:get_variable($_XDOCTX,'BizDaysOld') + 5)
    end if?>
    <?xdoxslt:get_variable($_XDOCTX, 'BizDaysOld')?>
    It doesnt get into the loop at all.
    Also, can somebody tell me if there is BIP equivalent method for "weekday" method in Actuate? Weekday method in actuate gives the day of the week.

    If you are checking for only one condition and setting the value then you can use
    <?if: ((xdoxslt:get_variable($_XDOCTX, 'BizDaysOld')) > 0 and (xdoxslt:get_variable($_XDOCTX, 'BizMonth'))=9)?>
    <?xdoxslt:set_variable($_XDOCTX, 'BizDaysOld', xdoxslt:get_variable($_XDOCTX,'BizDaysOld') + 5)?>
    <?end if?>
    Though you can use multiple if's to handle multiple checks, it can be efficiently done using choose, when. This is similar to if-else if -else structure
    <?choose:?>
    <?when: ((xdoxslt:get_variable($_XDOCTX, 'BizDaysOld')) > 0 and (xdoxslt:get_variable($_XDOCTX, 'BizMonth'))=9)?>
    <?xdoxslt:set_variable($_XDOCTX, 'BizDaysOld', xdoxslt:get_variable($_XDOCTX,'BizDaysOld') + 5)?>
    <?end when?>
    <?end choose?>
    for ur second condition include additional when clause
    Edited by: Kavipriya on Aug 3, 2010 8:54 AM

  • How to call a variable with a loop count in it

    First - I have a variable called "stages" this is a number
    that can vary. Because it can vary I want to run things in a loop
    based on the number that comes up as the stages variable amount.
    Second is a loop
    <cfloop index="riderCount" from="1" to "9">
    Next, I have a query
    <cfquery name="getPts" datasource="#application.dsn#">
    SELECT *
    FROM fantasy_racers
    WHERE proName='#pro#''
    </cfquery)
    ** Note: variable pro is set before the query **
    I have colums in my table: pts1, pt2, pts3, etc. all the way
    to pts25 for each pro in the table.
    Now to the heart of the matter
    I want to get the amount in each column. EX.: #getPts.pts1#
    but since the number of stages can vary I don't want to hard
    code for 25 outputs when there may only be 7
    so how can I call the column amount but utilize a ridercount
    in place of the number
    #getPts.pts
    ridercount#

    You can reference query variables in an array-of-structures
    notation:
    myQuery["MyColumn"][row]
    so you could do something like this:
    #getPts["pts" & riderCount][1]#
    Combine that syntax with Query.CurrentRow and
    Query.recordCount and you should be able to put a loop together
    that solves your problem.

  • Setting session variable names based on variables in a loop

    I am trying to set up a loop that sets up a list of variables based upon a list, by looping over the list and setting the session.NAME:
    <CFLOOP list="#fieldnames#" index="fieldname">
    <cfset session.#fieldname# = "1">
    </CFLOOP>
    It does not seem to like session.A_CF_VARIABLE . so session.#fieldname# does not work, I get an error
    A CFML variable name cannot end with a "." character.
    The variable session. ends with a "." character. You must supply an additional structure key or delete the "." character.
    Do I have to wrap it a different way?
    Thanks
    Mark

    ahh. great. that fixed the loop problem. My second problem now appears that I am not picking up the correct data.
    My test data has a form post with field names EMAIL and GENDER, and then I was trying to write session.email = VALUE_OF_FORM_FOR_EMAIL .. session.gender = VALUE_OF_FORM_FOR_GENDER, but what I am actually doing is writing the values EMAIL and GENDER into the session. so session.email has the value EMAIL.. and not what I typed into the form.
    I guess it's because the fieldname in the index is also used as the name in the form and it's confusing it, so it goes for the wrong one, not the value from the form.
    the alternative would be to append something to the name of each field in the form.. so email is F_email and F_gender... although i tried this and using <CFSET session[fieldname] = "F_#fieldname"> but that threw an error, maybe just a formatting issue. I'd prefer to try and make it work without appending anything to the form names
    Here's some test code that has the form fields hard coded -->
    <CFSET fieldnames="email,gender">
    <CFSET email = "[email protected]">
    <CFSET gender = "M">
    <CFLOOP list="#fieldnames#" index="fieldname">
    <cfset session[fieldname] = '#fieldname#'>
    </CFLOOP>
    Thanks once again for the help
    Mark

Maybe you are looking for