How to stop a "for" loop
Hello,
Do you know how I can stop a for loop ? because when I click on the stop switch on my front panel, the VI don't stop and continue to run the loop.
Peter.
Labview 2010
Solved!
Go to Solution.
Peter,
It sounds like you need a while loop, not a for loop. A button or switch does not traditionally control iterations of execution for a for loop.
Please post your code so we may help better.
-Chazzmd
Similar Messages
-
How to stop a while loop in LabVIEW from a C program
How to stop a while loop in LabVIEW from a C code
hi
I think by creating dll you can stop the while loop from your C program.For that you just create dll (Dynamic Link Library) for the VI which has that while loop.
Anyway can u please explain ur requirement clearly. -
How do I use For loop to check each node and import them to a new document?
In my function I would like to use a For loop to get all the statutes (xml) inside the object
objXmlBcaResponseDoc. In my case there are 2 statutes. I would like the output to look like the one I have posted here below. I am not sure how to do the For loop. The commented For loop is from another function but it is not working inside
this function.
The output is added into the **objXmlResponseMessageDoc** object and should look like this with 2 statutes (ns1:Statute) and a totalCount=2
<BasicSearchQueryResponse xmlns="http://crimnet.state.mn.us/mnjustice/statute/service/4.0">
<StatutesXml>
<Statutes runType="Request" runDateTime="2015-03-17T10:23:04" totalCount="2">
<ns1:Statute xmlns:ns1="http://crimnet.state.mn.us/mnjustice/statute/messages/4.0">
<StatuteId xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">8471</StatuteId>
<Chapter xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">60</Chapter>
<Section xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">55</Section>
<Subdivision xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0"/>
</ns1:Statute>
<ns1:Statute>
<StatuteId xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">9722</StatuteId>
<Chapter xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">90</Chapter>
<Section xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">25</Section>
<Subdivision xsi:nil="true" xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0"/>
</ns1:Statute>
</Statutes>
</StatutesXml>
</BasicSearchQueryResponse>
My xml doc is found inside objXmlBcaResponseDoc Here is xml inside
objXmlBcaResponseDoc object
<BasicSearchQueryResponse xmlns="http://crimnet.state.mn.us/mnjustice/statute/service/4.0">
<ns1:Statutes xmlns:ns1="http://crimnet.state.mn.us/mnjustice/statute/messages/4.0">
<ns1:Statute>
<StatuteId xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">8471</StatuteId>
<Chapter xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">60</Chapter>
<Section xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">55</Section>
<Subdivision xsi:nil="true" xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0"/>
</ns1:Statute>
<ns1:Statute>
<StatuteId xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">9722</StatuteId>
<Chapter xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">90</Chapter>
<Section xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">25</Section>
<Subdivision xsi:nil="true" xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0"/>
</ns1:Statute>
</BasicSearchQueryResponse>
Here is my function
Function GetStatutesByChapter(ByVal aobjXmlGetStatuteRequestNode As XmlNode, ByVal aobjXMLNameSpaceManager As XmlNamespaceManager, ByVal aobjBroker As ServiceCatalog.Library.v4.Broker) As XmlDocument
Dim objXmlRequestMessageDoc As XmlDocument
Dim objXmlResponseMessageDoc As XmlDocument
Dim intCount As Integer
aobjBroker.PostMessageWarehouseInformationalMessage("Chapter found.", 1)
objXmlResponseMessageDoc = New XmlDocument
'Add the first element into the document GetStatuteByChapter with its namespace
objXmlResponseMessageDoc.AppendChild(objXmlResponseMessageDoc.CreateElement("BasicSearchQueryResponse", "http://crimnet.state.mn.us/mnjustice/statute/service/4.0"))
'Build the initial response document
objXmlResponseMessageDoc = New XmlDocument
'Add the first element into the document GetStatutesResponse with its namespace
objXmlResponseMessageDoc.AppendChild(objXmlResponseMessageDoc.CreateElement("GetStatutesResponse", "http://www.courts.state.mn.us/StatuteService/1.0"))
'Add a child node to the GetStatutesResponse node
objXmlResponseMessageDoc.SelectSingleNode("ss:GetStatutesResponse", aobjXMLNameSpaceManager).AppendChild(objXmlResponseMessageDoc.CreateElement("StatutesXml", "http://www.courts.state.mn.us/StatuteService/1.0"))
objXmlResponseMessageDoc.SelectSingleNode("ss:GetStatutesResponse/ss:StatutesXml", aobjXMLNameSpaceManager).AppendChild(objXmlResponseMessageDoc.CreateElement("Statutes", "http://www.courts.state.mn.us/StatuteService/1.0"))
'Convert the node Statutes into an element and set the runType attribute (runType="Request") by adding it's value Request
CType(objXmlResponseMessageDoc.SelectSingleNode("ss:GetStatutesResponse/ss:StatutesXml/ss:Statutes", aobjXMLNameSpaceManager), System.Xml.XmlElement).SetAttribute("runType", "Request")
'Convert the node Statutes into an element and set the attribute (runDateTime="2015-03-05T10:29:40") by adding it
CType(objXmlResponseMessageDoc.SelectSingleNode("ss:GetStatutesResponse/ss:StatutesXml/ss:Statutes", aobjXMLNameSpaceManager), System.Xml.XmlElement).SetAttribute("runDateTime", Format(Now, "yyyy-MM-ddTHH:mm:ss"))
'Create the BCA request message
objXmlRequestMessageDoc = New XmlDocument
objXmlRequestMessageDoc.AppendChild(objXmlRequestMessageDoc.CreateElement("ns:BasicSearchQueryRequest", aobjXMLNameSpaceManager.LookupNamespace("ns")))
objXmlRequestMessageDoc.SelectSingleNode("ns:BasicSearchQueryRequest", aobjXMLNameSpaceManager).AppendChild(objXmlRequestMessageDoc.CreateElement("ns1:BasicSearchCriteria", aobjXMLNameSpaceManager.LookupNamespace("ns1")))
objXmlRequestMessageDoc.SelectSingleNode("ns:BasicSearchQueryRequest/ns1:BasicSearchCriteria", aobjXMLNameSpaceManager).AppendChild(objXmlRequestMessageDoc.CreateElement("ns2:Chapter", aobjXMLNameSpaceManager.LookupNamespace("st")))
objXmlRequestMessageDoc.SelectSingleNode("ns:BasicSearchQueryRequest/ns1:BasicSearchCriteria", aobjXMLNameSpaceManager).AppendChild(objXmlRequestMessageDoc.CreateElement("ns2:Section", aobjXMLNameSpaceManager.LookupNamespace("st")))
objXmlRequestMessageDoc.SelectSingleNode("ns:BasicSearchQueryRequest/ns1:BasicSearchCriteria", aobjXMLNameSpaceManager).AppendChild(objXmlRequestMessageDoc.CreateElement("ns2:Subdivision", aobjXMLNameSpaceManager.LookupNamespace("st")))
'Uncomment last working section below
objXmlRequestMessageDoc.DocumentElement.SelectSingleNode("ns1:BasicSearchCriteria/st:Chapter", aobjXMLNameSpaceManager).InnerText = aobjXmlGetStatuteRequestNode.SelectSingleNode("ss:Statute/ss:Chapter", aobjXMLNameSpaceManager).InnerText
'check if there is a section and or subdivision if it is there then set the value
If Not (aobjXmlGetStatuteRequestNode.SelectSingleNode("ss:Statute/ss:Section", aobjXMLNameSpaceManager) Is Nothing) Then
objXmlRequestMessageDoc.DocumentElement.SelectSingleNode("ns1:BasicSearchCriteria/st:Section", aobjXMLNameSpaceManager).InnerText = aobjXmlGetStatuteRequestNode.SelectSingleNode("ss:Statute/ss:Section", aobjXMLNameSpaceManager).InnerText
End If
If Not (aobjXmlGetStatuteRequestNode.SelectSingleNode("ss:Statute/ss:Subdivision", aobjXMLNameSpaceManager) Is Nothing) Then
objXmlRequestMessageDoc.DocumentElement.SelectSingleNode("ns1:BasicSearchCriteria/st:Subdivision", aobjXMLNameSpaceManager).InnerText = aobjXmlGetStatuteRequestNode.SelectSingleNode("ss:Statute/ss:Subdivision", aobjXMLNameSpaceManager).InnerText
End If
'check if there is a section and or subdivision if it is there then set the value
aobjBroker.PostMessageWarehouseSnapshot(objXmlRequestMessageDoc.OuterXml, "Request Message", 1)
'Call the BCA service
intCount = 0
'This is where I want to use a For loop to check for the statutes found using the Chapter
'Loop through each Id
'For Each objXmlStatuteIdNode In aobjXmlGetStatuteRequestNode.SelectNodes("ss:Statute/ss:StatuteId/ss:Id[string-length(.)>0]", aobjXMLNameSpaceManager)
'Create the BCA request message
'objXmlRequestMessageDoc = New XmlDocument
'objXmlRequestMessageDoc.AppendChild(objXmlRequestMessageDoc.CreateElement("ns:SingleStatuteRequest", aobjXMLNameSpaceManager.LookupNamespace("ns")))
'objXmlRequestMessageDoc.SelectSingleNode("ns:SingleStatuteRequest", aobjXMLNameSpaceManager).AppendChild(objXmlRequestMessageDoc.CreateElement("ns:statuteId", aobjXMLNameSpaceManager.LookupNamespace("ns")))
'objXmlRequestMessageDoc.DocumentElement.SelectSingleNode("ns:statuteId", aobjXMLNameSpaceManager).InnerText = objXmlStatuteIdNode.InnerText aobjBroker.PostMessageWarehouseSnapshot(objXmlRequestMessageDoc.OuterXml, "Request Message", 1)
'intCount = intCount + 1
'objXmlBcaResponseDoc = New XmlDocument
'File name is BCASearchQueryResponse.xml
'objXmlBcaResponseDoc.Load("\\j00000swebint\mscapps\deve\appfiles\temp\BCASearchQueryResponse.xml")
'objXmlResponseMessageDoc.DocumentElement.SelectSingleNode("ss:StatutesXml/ss:Statutes", aobjXMLNameSpaceManager).AppendChild(objXmlResponseMessageDoc.ImportNode(objXmlBcaResponseDoc.DocumentElement.SelectSingleNode("ns1:Statute", aobjXMLNameSpaceManager), True))
'Next
'Count how many Statute nodes found
CType(objXmlResponseMessageDoc.SelectSingleNode("ss:BasicSearchQueryResponse/ss:StatutesXml/ss:Statutes", aobjXMLNameSpaceManager), System.Xml.XmlElement).SetAttribute("totalCount", CStr(intCount))
Return objXmlResponseMessageDoc
End FunctionWhat is XPath and what does it do that you're impressed with?
Yes, I see your link, but give me the abbreviated elevator speech on what it is please. It has me curious.
http://searchsoa.techtarget.com/definition/XPath
http://www.techrepublic.com/article/easily-navigate-xml-with-vbnet-and-xpath/
http://www.techrepublic.com/article/using-xpath-string-functions-in-xslt-templates/
The way that all this is being used by me now on a project is the HTML controls on the screen are built by XML not only about what the controls are and their attributes, but the data from from the database is XML too with both going through transfermations
vis XSLT as the HTML controls are built dynamically by XML data for the controls and the XML database data with decision being made in the transfermation on the fly.
There are many usages with Xpath not just this one I am talking about with Xpath. You can do the same kind of thing with XAML and WPF forms as they are dynamically built. But it goes well beyond what I am talking about and the usage of Xpath. Xpath 3.0
is the latest version.
http://www.balisage.net/Proceedings/vol10/html/Novatchev01/BalisageVol10-Novatchev01.html
Thanks - I'll look into that at some point.
Still lost in code, just at a little higher level. -
How to stop after first loop operation over?
Hi friends.
How to stop after first loop operation over?
I have a loop operation in module pool program.
After first loop over I want to stop.
I used the STOP keyword, but it is going to dump.
Thanking you.
Regards,
SubashHey,
The statement STOP is forbidden in methods and, since release 6.10, leads to an uncatchable expection during the processing of screens called with CALL SCREEN...
As they said above, use a EXIT statement to fix this DUMP...
Regards,
Diogo Carvalho -
How to stop a while loop after certain time using Elapsed time vi
how to stop a while loop after certain time using Elapsed time vi.
Hi Frankie,
Just place the Elapsed Time VI inside the WHILE loop, and wire the 'Time Has Elapsed' output to the conditional terminal in the lower right corner (which should be set to 'stop if true' by default).
In the future, please post your LabVIEW questions to the LabVIEW Forum. You have a much better chance of getting your questions answered sooner, and those answers can then help others who are searching the LabVIEW forums. Thanks!
Justin M
National Instruments -
How to pause and stop two "for loops" in an event
Hi
The main menu runs first and then goes to reading menu. After "Start Reading" button is pressed, the reading process will take readings.
1) During reading process, if the "Pause Reading" button is pressed, I want that the two "for loops" are stopped and the two "for loop" counters do not reset. After the "Start Reading" button is pressed, the two "for loops" will continue to run.
2) During reading process, if the "Stop Reading" button is pressed, I want that the two "for loops" are stopped and the two "for loop" counters are reset. After the "Start Reading" button is pressed, the two "for loops" will run again.
The attached two VIs are simplified my real application. Any help will be appreciated.
Thanks
Steve
Attachments:
Main Menu Test.vi 9 KB
Reading Menu Test.vi 23 KBYou can't have those loops inside of the event structure. Currently, when you press the start button, the reading has to finish before the event case finishes. This will prevent the stop can cancel buttons from being processed by the event structure.
You need another loop that can recieve commands from the event loop. Look up the Queued Message Handler. That should get you a good start on the command process.
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines -
How to stop a while loop of event structure from a main vi
Hello;
sorry for my english
I have to stop a subvi from my main vi, the subvi contains a while loop and an event structure so I need to stop this loop while directly from my main vi I have tried global variable but it did not work
any help please or example !!!
Solved!
Go to Solution.
Attachments:
stop a while loop and event structure from main vi.png 16 KBIYED wrote:
Hello;
sorry for my english
I have to stop a subvi from my main vi, the subvi contains a while loop and an event structure so I need to stop this loop while directly from my main vi I have tried global variable but it did not work
any help please or example !!!
If this is an example of how your code looks, I'd clean it up before the developer who has to work on it next hits you over the head with his LabVIEW Style Book.
Bill
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all. -
Dear All,
I have a doubt over here...In my frame, I have two buttons...one is "START" and the other is "STOP". If the "START" button is clicked, i am calling a method in which a "FOR LOOP" will start running for 100 times. If the "STOP" button is clicked, I should stop the said for loop, in the middle itself....how to do the above...
any suggestions, solutions, ideas are higly appreciated...
bye,
Sakthivel S.u can use a boolean variable for that.in ur loop check that boolean if it is true perform the loop task.and when stop is pressed make that boolean false.and in ur loop if boolean is fale break the loop.i hope u r also using thread.sleep to minimize the processor usage.
-
Stopping a For Loop, part 2
Hello. Thank you everyone for your help, getting to this point. I asked for help to create a stop condition, while a For Loop is running. I was given many ideas and selected the one that used local variables. It works well however, if I am in the "Test in progress" state, in the first For Loop, and the "Stop" button is selected from the front panel, when it stops the Vi, it sends the value "5" to the second For Loop before going to the "End" state, which puts it to "0", then stops the Vi. What this Vi is doing is feeding 0-200VDC signal to an eddy current sensor, then it feeds 200-0VDC going the other direction. I have tried sequencing, putting in timers and a few other goofy things but I can not get the Vi to stop in the first For Loop, without the Vi performing the initial "5" to the second For Loop. Someone had mentioned using an event handler, in my previous post. I practiced for quite some time, trying to understand how to use an event handler but am not much the wiser. Any and all input would be greatly appreciated.
altenbach wrote:
ceilingwalker wrote:
You are autoindexing way too many thing between the two FOR loops I was doing this to create a data dependency, at least that was my thought process behind it. As far as the physical channels and VISA refnums, I did it this way so I didn't create more controls for the front panel. Being my first project, I am very certain my logic is flawed, this is why I like posting here and getting feedback from
You have many visa sessions that (hopefully) never change during the execution of the loops, so why woold you turn them into an array of 11 identical elements just to autoidex them out again at the next loop. Change the tunnels to no autoindexing and things would look cleaner. Why are these session controls inside the loop? Are you expect them to be changeable during loop execution or would that screw up the results?
Wounld't it be easier to simply create an up&down ramp once and use a single FOR loop, autoindexing on the ramp? You have way too much duplicate code!!!
If you don't want the second loop to run when the first one is ended prematurely with the stop button, put it in a case structure I tried a Case structure for the second For Loop. I couldn't find a way to change conditions that didn't affect the Vi's overall performance.
Then show us what you tried! That should be trivial to implement. Why would a case structure affect performance? Makes no sense!
Why would a case structure affect performance? Makes no sense! I used a boolean operator to change the state. When I used a false, it worked for that problem but shut down my Vi before the second For Loop.
Wounld't it be easier to simply create an up&down ramp once and use a single FOR loop, autoindexing on the ramp? You have way too much duplicate code!!! I tried using one For Loop to begin with but because I had to ramp up, then ramp down, I couldn't figure out how to use just one. I needed an Add function for the ramp up and a Subtract function for the ramp down.
Why are these session controls inside the loop? Are you expect them to be changeable during loop execution or would that screw up the results? No Sir, the values are not changed during operation. I did this because I wanted it to display the data on the front panel, during operation of the Vi. For display only.
-
How to stop validation for Back action in ADF
Hi,
In ADF form, I have a 'Back' button which should just go back to the previous page. But when I select 'Back' button, the form is validated again and I do get validation error messages.
How can I stop validation for these type of simple actions?
Please do let me know.
Thanks,
priya.SYou might find this blog post useful in finding a generic solution to your problem:
http://one-size-doesnt-fit-all.blogspot.com/2007/02/jdeveloper-and-art-of-rollback.html
CM. -
How to stop request for admin password when sending files to trash?
I am requested the admin password when ever sending a file to trash using the mouse or the context menu.
How to stop this annoying request?
It was not like this before.
I am working on a non admin account for security reasons. I got admin details here of cause.
Thanks for you help!
Till KopperI gave my working account admin abilities in the system preferences. logged out and back in. Run the command line "sudo rm -rf ~/.Trash" as Topher Kessler suggested. Now my own password was accepted (before this ine and the admins accounts one failed). No there is no annoying request for the admin passowrd when sending a file to trash. changed my work account for no admintrative in the system prefs and logged out and in.
Problem solved.
THanks to Topher Kessler!
(how to give you now the 10 point you deserve?) -
How to stop suggestions for words when texting
How do I stop suggestions for words when texting?
Settings>General>Keyboard>Auto-Correction>Off.
-
How to stop Depreciation for some assets & start again.
Dear Friends,
We have a requirement where we have to stop Depreciation for some assets as they are not in use and again post depreciation when they put in use.
For ex: Asset Value is 10,000 and monthly Depreciation is 100. Asset has been depreciated for first 6 periods in year with 100 each in every month & we want to stop depreciation for coming 3 months and post depreciation when they put in use. Asset should not be depreciated when they are not in use and calculate regular 100 if we run depreciation again if we put in use. So total Depreciation of the asset for the year should be 900 (First 6 Months & last 3 months).
Please explain step by step process to do this and your kind cooperation to solve this issue is highly appreciated.
Points will be rewarded for sure if my problem solves.
Thanks & Regards,
Naveen Kumar.Go to AS03 Asset Master/Dep tab and observe the dep key
Goto AFAMA and select that dep key and click on assignment of calculation methods
You can see last row for shutdown field and select YES
Go to asset master at AS02/Time dependent data and select shutdown check box and enter period
If shutdown check box is not available goto as03 and goto menu environment-screen layout and master data and identify the screen layout number
Go to SPRO-Financial Accounting (New)-Asset Accounting-Master Data-Screen Layout-Define Screen Layout for Asset Master Data-Define Screen Layout for Asset Master Data-
Select your screen layout and click on logical field groups and select 3 (Time dependent data) and click on field group rules and make shutdown field as optional.
This will allow you to change the shutdownfield asset master data.
Srinivas -
How to recover the for loop or seq() from a sequence result
assume generate a sequence with code
for i in 1..2 do
append 1 to a list to represent outer loop
for j in 1..3 do
append 2 to list to represent inner loop
result in [1,2,2,2,1,2,2,2]
is it possible to recover for loop code and seq() function code from [1,2,2,2,1,2,2,2] ?
with fold or unfold or other method?
computing nightmareYes; and in doing so, your program will converge towards being an exemplar of the generalization of
Greenspun's tenth rule to any arbitrary language (rather than just 'C' or Fortran). -
How to stop a while loop which contains a timed loop
Hi,
I'm a new hand to labview, and I'm using labviw 7.1, NOT 8.x. I'm trying to do a measurement, in which the flow would look like the attached file (I have stipped all hardware related components to make it easy to read). My questions are:
1. In Loop 3, when the comparison (x>20.85) is true, Loop1, Loop2 and Loop3 are stopped, why it won't quit the while loop (I have wired it to while loop stop)?
2. When it is running, I click on stop button, why it won't stop?
Thanks!
Attachments:
SyncTimedLoop32.vi 228 KBhwm wrote:
2. When it is running, I click on stop button, why it won't stop?
The stop button is read outside of the inner while loops. So the inner while loops will continue to run until their stop conditions are met.
hwm wrote:
1. In Loop 3, when the comparison (x>20.85) is true, Loop1, Loop2 and Loop3 are stopped, why it won't quit the while loop (I have wired it to while loop stop)?
It seemed to me like it would, but sometimes it seemed like I had to set change the numeric value one more time before it would. You have a very odd structure there by placing the event structre inside the while loop with the other loops. I think you may be running into issues where events are getting queued up in the event structure, or race conditions between when the event structure might execute relative to the other loops. It is all very odd and difficult to predict all the ways these structures might interact and relative timing. Usually event structures would belong in their own parallel while loop. I think you need to rethink exactly what you are trying to do here. It probably isn't event necessary to use the stop timed structure functions. A local variable or a notified to pass the "Stop status" from loop 3 to the other loops (or the separate event structure loop to the other 3) would probably be better.
Maybe you are looking for
-
How to use user defined function in select query using Toplink
Hi Friends I am little bit of new in Toplink stuff... so please help me... I have to database functions 1. encrypt and 2. decrypt. I want to exceute the following sql query using toplink select port, database, user_name, decrypt(encrypt('String which
-
Scrolling selected text with Indesign CS6 to show different font style
Hi, I recently found I could highlight a paragraph and using font character style I could scroll through fonts changing whole paragraphs, I can't remember how I did this, I know it's a new feature with CC, I'm on CS6
-
How do I install the card into the
I received my new card in the mail today and it came with no instructions. I know it goes in the PCI slot but what am I supposed to do with the cord? I've searched and searched, all I keep coming up with anywhere are how to install the drivers which
-
Safari could not open because server stopped responding
My iphone4s can not open safari and it says the server has stopped responding. I have powered off several times and have cleared the safari history. nothing works. what now?
-
Airport utility can't find my airport base station
Im trying to set up a wireless internet at home. I have a comcast cable internet connected to motorola sb120 cable modem and I connected an ethernet cable from the modem to my aiport base station. when I open the airport utility in my macbook (also