Event structure vs case structure?

I am developing an application that is fairly user input based... lots of boolean control buttons to do different things.
In the past, I have avoided "value change" event structures, and instead went with a while loop, stacked sequence, and series of case structures. After having done it, I decided this was a terrible idea. This time, I intend to build an array from the booleans, convert it to a number, and feed it in to a single case structure. This will give me the option to add cases for different combinations of the booleans being pressed.
I guess the question is: What is the best method for doing something like this?  Does one have advantages over the other?
Edit: I wasn't that clear.  I would like a comparison between the "value change" event structure method, and just feeding everything in to an array -> case structure.  I also am worried that with the bool array -> case structure that I will run in to problems where I end up with too many control variables, and the value of the resulting number gets ugly very quickly. The application has several buttons... next, last, save, load, several different configure setup buttons etc.
Thanks!
Solved!
Go to Solution.

Aalenox wrote:
I am developing an application that is fairly user input based... lots of boolean control buttons to do different things.
In the past, I have avoided "value change" event structures, and instead went with a while loop, stacked sequence, and series of case structures. After having done it, I decided this was a terrible idea. This time, I intend to build an array from the booleans, convert it to a number, and feed it in to a single case structure. This will give me the option to add cases for different combinations of the booleans being pressed.
I guess the question is: What is the best method for doing something like this?  Does one have advantages over the other?
Edit: I wasn't that clear.  I would like a comparison between the "value change" event structure method, and just feeding everything in to an array -> case structure.  I also am worried that with the bool array -> case structure that I will run in to problems where I end up with too many control variables, and the value of the resulting number gets ugly very quickly. The application has several buttons... next, last, save, load, several different configure setup buttons etc.
Thanks!
Event structure. Among other things, it will allow your loop to "sleep." then wake up when an event happens. With a case structure it's going to be constantly polling. Event structure is pretty much always the right way to go in newer versions of LabVIEW that have it available. I assure you, your first solution was aboslutely wrong and you noticed that, your second is better and was common the way before event structures existed, now that event structures exist, you should go with those.
CLA, LabVIEW Versions 2010-2013

Similar Messages

  • Event structure or case structure

    I have some case structures wired to buttons.  When each button is true, code inside the corresponding case structure executes.  `What are the advantages/disadvantages of using an event structure instead of a case structure?
    Ron Deavers, CLD

    Place an indicator for the iteration terminal of the main loop to see an obvious difference
    Your case structures must be in a loop that constanty runs. If you don't put a delay in the loop, it consumes all CPU, but if your delay is too long, it takes a moment to react to the button changes. The loop spins all the time, no matter if you press buttons or not.
    Your event structure also sits in a loop, but nothing happens until you press a button. Now the event structure triggers IMMEDIATELY, executes the event case, and then waits for the next event. The loop does not spin unless needed.
    You can even mix the functions by using a timeout event. Code in the timeout event occurs at regular intervals, but at any time, any of the other events can take over.
    LabVIEW Champion . Do more with less code and in less time .

  • Replace Diagram Disable Structure by Case structure?

    I may be missing something but at least in LV 2010, it appears only possible to replace a "Diagram Disable Structure" by a "Conditional Diagram Disable Structure".
    I don't see why it is not possible to replace it by a case structure... The content is very similar and I have faced occurences where I would toy around between different versions of my code and eventually decided that I wanted to offer the user the possibility to choose between them using an enumerated control (or Boolean). Currently you have to rewrite the code in a newly dropped case structure, which is a waste of time. I guess I could stop using Diagram Disable structures altogether, but I most of the time use them for their intended use, so that would be a step backward in functionality if I forced myself to use case structures "in case" I would later want to offer these different cases to the user (which is something that I can't always predict).
    Solved!
    Go to Solution.

    You are not alone.
    http://forums.ni.com/t5/LabVIEW-Idea-Exchange/Add-the-ability-to-replace-a-disable-structure-with-a-...

  • Case structure with more than 200 cases, slower lab view app

    Problem Description :
    i am currently making a vi which compose of a simple case structures, a case structure with more than 200 cases, what i noticed is that the more i added cases the slower the labview reacts, it takes time for me to route wire on each of the cases.
    i dont know if there are any setting in the labview environment that i can increase the buffer size? i dont know... but its getting slow (only on the
    vi with more cases in a case structure)
    mytestautomation.com
    ...unleashed the power, explore and share ideas on power supply testing
    nissanskyline.org
    ...your alternative nissan skyline information site

    Can you clarify what you mean by "slow". Does it run more slowly or does it feel sluggish during editing?
    Could you attach the actual VI?
     Overall, I agree with the notion of local variable overuse. For example, you read the same local variable twice in the same case. Is there a need for this? Is there a chance that it varies between the two reads? Typically, you would place the terminal in front of the case structure and wire to all the locations where you need the value. This ensures that the data is consistent. Still, this should not cause any slowdown problem.
    (On a sidenote, the code in the upper left corner is inefficient. You convert the same data to lower case with each iteration, so you might want to place this before the loop and do it only once (well, if you are lucky, LabVIEW will fold the operation, but still....). Also your "index array" operation can be replaced by autoidenxing of the 2D array on the outer loop boundary.)
    LabVIEW Champion . Do more with less code and in less time .

  • Transfering a case structure to event structure

    Hi, I am trying to transfer case structures that are currently set up to a control that if on prompt the user where to save and then save all following files to that location till end of program and if off the do nothing. I would like to enable these to be switched on and off at any point and know to use an event structure. The problem is I am new to coding with an event structure and have been able to get the button to work but not continuously save. I attached a screen shot of the original case structure and was wondering if someone could show me how to change it to the event structure format with the same functionality. I'm getting a little lost and confused. Thanks!
    Attachments:
    alltruecases.jpg ‏534 KB

    I can't attach the vi due to the size and I do not think a simplified piece of code is going to help. I did however go through and stitch two jpegs together of the main two sequences. hopefully this gives a better idea of what I am trying to do and where to go from here. thank you.
    Attachments:
    1.jpg ‏669 KB
    2.jpg ‏317 KB

  • Case structure & event structure

    1.What are the disadvantages of case strucure?
    2.What are the advantages of event structure?

    Are these test questions? I could name 10 for each, but why are you asking?
    While there are often many ways to accomplish the same thing, Case structures and Event structures serve different purposes. Straight from the Help file:
    Case Structure
    Has one or more subdiagrams, or cases, exactly one of which
    executes when the structure executes. The value wired to the selector terminal
    determines which case to execute and can be Boolean, string, integer, or
    enumerated type. Right-click the structure border to add or delete cases. Use
    the Labeling tool to enter value(s) in the case selector label and configure the
    value(s) handled by each case.
    Event Structure (Not in Base Package)
    Has one or more
    subdiagrams, or event cases, exactly one of which executes when the structure
    executes. The Event structure waits until an event happens, then executes the
    appropriate case to handle that event.
    Right-click the structure border to add new event cases and configure which
    events to handle. Wire a value to the Timeout
    terminal at the top left of the Event structure to specify the number of
    milliseconds the Event structure should wait for an event to occur. The default
    is –1, indicating never to time out.

  • Start event from case structure

    I'm running my main programm inside an event of an eventstructure.
    Beside this main event I additionally have 3 other events in this event structure.
    To save "screen space" I would like to start indirectly one of my other events from a case
    placed inside another event.
    Is this possible - would be glad if you have an example.

    You are still completely misunderstanding the purpose of the event structure (see also my answer the other thread).
    The main code of the program does NOT belong inside an event structure. What good is an event structure if it is tied up indefinitely inside one of the event cases???
    An event structure is most useful for dealing with interactions by the user and must be ready to handle those at any time. It is not a tool to "save screen space" (whatever that means). If you are running out of diagram space, consider wrapping your code segments into subVIs.
    LabVIEW Champion . Do more with less code and in less time .

  • Event structure inside a case structure

    Hi,
    I've got a problem w/ my porgram, and managed to boil it down to this
    simple example.  The program basically hangs if you change the
    Numeric value when the boolean is false.  I don't understand
    why.  I suspect it has to do with the way event structures are
    treated, but if someone cou please explain this I'd be greatful.
    Also, now imagine I have 7 numeric controls, handled by 7 cases in that
    event structure, and I actually want to do things in response to the
    value change for each.  Can someone suggest an elegant way to do
    that?  I thought what I had here was a good design, but apparently
    not.
    Bjorn
    (I'm using labview 7.1)
    Attachments:
    EventInCase.vi ‏24 KB

    It is generally a bad idea to place event structures into cases. Events structures need to be able to breathe.
    Maybe you can redesign your program and place the case structure inside the event structure, for example? (Also have a look at the online help for the event structure, especially the link "caveats and recommendations for using events ".)
    Detailed analysis:
    Your event case for the numeric is set to "lock front panel until event completes".  If you change the numeric while the case is false, the evet structure cannot execute, so the front panel locks forever. The observed behavior is as expected. All clear?
    In addition, if the case is false, the main loop spins at nearly infinite rate, consuming all available CPU. Place a small wait to be more cosiderate to everything else running on your rig.
    LabVIEW Champion . Do more with less code and in less time .

  • How can I determine whether to use an event structure or a case structure?

    I'm starting a large project and need a state machine. I can't decide on whether to use a case structure or event structure. Is there an article  or other information that describes criteria for selecting between the two approaches?
    Thank you,
    Chuck
    Solved!
    Go to Solution.

    Hi Chuck,
    Well case structures and event structures differ quite alot.  Here's a link for indepth information on Event Structures, and using them in state machines: http://zone.ni.com/devzone/cda/tut/p/id/2962.  Hopefuly this will help you make up your mind.  
    Let me know if you have any questions after reading it. 
    Regards,
    Dominic Walker
    Cardiff University
    Electrical and Electronic Engineering Student

  • Case structure/event counting

    Thanks so much everyone for your help. I was
    able to get it to work. I now have a second question that I have been
    wrestling with on my program for some time. I am hoping to be able to
    count the number of times each event happens, be it >0, <0 or 0.
    So far, I haven't been having a lot of luck on figuring this out.
    The
    way my program works is that the case structures control the opening of
    solenoid valves. I am running a while loop to keep the program running,
    but would like to be able to at least count the number of times each of
    the cases are true in an effort to figure out the amount of time each
    of the solenoids is open during a run.
    What I really need
    to do is be able to run each case for a maximum of 10 minutes each, and
    then stop the case from running. I know this is an in depth problem,
    but simply counting the number of times each of the cases run would be
    a huge start for me.
    Thanks again for the help on the other problem.
    Tim

    You need three different counters, one for each event. Right now you increment the same number, irrespective of case, so you might as well do this outside the case structure or even just use the iteration terminal. Also, the counter should be blue (I32). You also need to initialize the shift registers.
    Here's a simple example (LabVIEW 8.0) that uses an array of three elements to keep count of the three cases. See if this makes sense.
    Message Edited by altenbach on 08-27-2008 09:30 AM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    countCases.vi ‏13 KB

  • Event in case structure

    Dear all,
    I am using Event Structure in a Tab Control.
    On page 1, there is a Table Control and when the mouse is clicked on it, it returns the Cell Value. The event is working ablsolutely fine, but the problem is i have no idea how to Stop the Event.
    I am attaching my Vi here. Pls have a look at it and let me know of a possible solution.
    Thanks,
    Ritesh
    Solved!
    Go to Solution.
    Attachments:
    Event in Tab.vi ‏18 KB

    ritesh024 wrote:
    But, it means that the Events in Page 1 are getting triggered even when the Control is on Page 2.
    That would take the unnecessary memory and time as there is no need for the events on Page 1 to run when the Control is on a different page.
    No, the event will not get "triggered", because if you are on the other tab it is impossible to fire the table event and a mouse up cannot occur. The event structure is in memory no matter what and placing it inside a case structure only complicates the code and can will lead to problems.
    The event structure should always be in the dataflow, the tab position is irrelevant. Never hide an event structures inside a case structure!
    Here's a quick example (LV 8.5). Tab 1 has your table and senses the cell position. Tab 2 has a light switch. As you can see there is no case structure needed.
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    Event_in_TabMOD.vi ‏19 KB

  • Multicolum​n listbox value change and mouse up event in one case of event structure

    Hello All,
    Am facing two problems:
    1. I have two multicolumn events, one is value change for deleting the rows of Multicolumn listbox and another one is mouse up for sorting the columns. But I can't combine both the events in one case. And if I create two separate cases then each time the event of mouse up executes and sorting takes place irrespective of selection of delete event.
    2. I have a selection VI in which user selects which parameter he wants to show it in a multicolumn listbox. I want this parameters to be retain or stored when next time I run the VI after closing it.
    Am using LabVIEW 11. Pls reply soon.
    Thanks & Regards,
    Manisha 

    try this
    Beginner? Try LabVIEW Basics
    Sharing bits of code? Try Snippets or LAVA Code Capture Tool
    Have you tried Quick Drop?, Visit QD Community.
    Attachments:
    Untitled 2.vi ‏12 KB

  • Run only once in case structure

    Hello,
    I have a menu set up that is wired to a case structure.  Of course the menu is some boolean buttons that are set to switch when pressed so the case will stay open as long as the button is true.
    inside that case I have another menu and a case structure that operates the same.  In one of these cases I have a piece of code that I only want to run once.  I have tried the while loop that runs once and a for loop that only runs once, but the section of code seems to run continuosly instead of just once.  It works ok if I use any of the latch functions but not the switch when pressed functions.  However, I need the button to stay pressed until the user is finished with that case.
    I really don't want to use an event structure as I was saving that for another piece of code that monitors inputs.
    Anyone have a suggestion?

    Typically, this works easiest with a shift register and and a boolean "implies" function.
    In the code example (see image), the button is set to "switch until released". (Of course you probably don't need the NOT, simply place your one-time code into the FALSE case )
    Message Edited by altenbach on 01-26-2007 01:52 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    implies.png ‏8 KB

  • How to get a case structure to execute only once in a loop

    I have a while loop that is monitoring temperature. Once the temperature meets or exceeds a given setpoint I want to start a timer. At this point I don't want to monitor the temperature anymore. That is, if the temperature should drop below the setpoint, I don't want to execute the case structure again when the temperture meets or exceeds the setpoint(the temp may oscillate about the setpoint for a given period of time). In any event, I need the case structure to execute only one time, not every iteration of the loop.

    You can put a local Boolean variable "Flag" inside that case structure and
    set "Flag" to False. Outside the case structure, use an "AND" function
    output to control the case structure. The "AND" function has two inputs. One
    goes to the comparison results between real temp and setpoint. The other
    inputs connects to the "Flag" variable. In this way, once you entered that
    case structure, the "Flag" will be turned to False, and then in next
    iteration, you won't get into the case again because the "AND" function will
    be False as your "Flag" is False now.
    Hope this helps.
    Rentian
    1. Inside the case structure, put a
    "BB Herman" wrote in message
    news:[email protected]..
    >I have a while loop that is monitori
    ng temperature. Once the
    > temperature meets or exceeds a given setpoint I want to start a timer.
    > At this point I don't want to monitor the temperature anymore. That
    > is, if the temperature should drop below the setpoint, I don't want to
    > execute the case structure again when the temperture meets or exceeds
    > the setpoint(the temp may oscillate about the setpoint for a given
    > period of time). In any event, I need the case structure to execute
    > only one time, not every iteration of the loop.

  • I want to create an array that goes into a case structure where each element in the array is an individual case and gets done in order

    I want to create an array that goes into a case structure where each element in the array is an individual case and gets done in order. Any ideas, I've been playing with the idea but have had no luck, is this even possible?

    Hi,
    Please check it out the attached Vi.. Is this you need?
    Sasi.
    Certified LabVIEW Associate Developer
    If you can DREAM it, You can DO it - Walt Disney
    Attachments:
    Event.vi ‏11 KB

Maybe you are looking for

  • Manual transfer problems

    Sometimes, when I'm clicking and dragging songs manually from i-tunes to the ipod, i get a "not allowed" symbol (circle with a diagonal line) as I move it over the ipod line, and it won't allow me to make the transfer. Almost all the other songs will

  • Clustering and Branded Zones

    After a bit of a struggle I have a Solaris 8 branded zone installed as a cluster resource and it will fail over perfectly happily. However I installed it by the old fashioned method of building the zone, installing it on one node and then adding it a

  • Please send tables used for this report.

    hi pls any one send all the tables names are used in this given report report: <b>Created report that display month-wise sales details by comparing with previous month and yearly sales details with selection criteria based on date.</b> thanks in adva

  • AmaroK 1.2-beta4 package

    I'm an amaroK developer, and want to start either maintaining the official amaroK package for Arch or/and start providing weekly CVS builds. amaroK 1.2-beta4 isn't out yet, but it will be soon, so here's a sneak peak. Please tell me how the package s

  • An error occurred (-42086) while connecting to the AirPlay device "Apple TV"

    I have 2013 Macbook air and recently while I'm streaming content to my apple tv, it kicks me off and displays (An error occurred (-42086) while connecting to the AirPlay device "Apple TV") on my mac. Anyone know how to fix this? Streaming to the appl