Showing results for 
Search instead for 
Did you mean: 

have to run event twice to get response

Go to solution

Hi, newbie here.  I made a little routine to take an ID number  entered by the user (generally 4 digits but not limited as such), and use an event structure to add an alpha prefix, and the current year as a suffix, then display the new string.  I'm trying to get a handle on how the event structure works, as well as the text, string, and date functions.  It works as it is but I have to run the event twice to get the right result.  Any suggestions or explanations are truly appreciated. 


PS  I also noticed that string and text functions don't work the same way.  The string control appended every time I entered a new ID number and would output its entire contents to the concatenate node and I couldn't figure out how to limit it to the current entry.   The text control gives me what I want but it only shows up in my "Express" menu, not classic or modern which would seem to have their own advantages in differing situations for formatting the screen, etc.   I suppose I could build another function to extract the desired portion but that seems like overkill.  Any hints? 


Thanks,  Jim

Message Edited by on 02-24-2010 12:56 PM
0 Kudos
Message 1 of 7
Just for funsies, here is the one with the string control.
Message Edited by on 02-24-2010 12:59 PM
0 Kudos
Message 2 of 7
Accepted by topic author

Does this do what you want it to do?


You have to have the string control read inside the A event case.

When you run your VI it read the string control before it waits at the event case. So if you do not enter the string before you hit the run arrow you will not get the correct string. Then when you run it the 2nd time the string is already in the string control for it to read.


That is why you had to run it twice.

Message Edited by Omar II on 02-24-2010 01:11 PM
Message 3 of 7

Wow, Omar, a 12 minute solution.  Thanks it works great!! 


Can I ask you why it's necessary to add the while loop?  In my mind the advantage of the event structure was to free up resources by not constantly polling buttons.  Again, newbie here, sorry for asking baby questions. 


Thank you, 



0 Kudos
Message 4 of 7

The while loop is needed to run the event structure more than once.  There is no polling going on.  The event structure waits for the event, executes it, goes into the next iteration of the while loop and waits again.


In your program without the while loop, the program runs, waits for the event, executes it, then its done.



Message 5 of 7
Thank you Ravens Fan (Vikings here).  I guess I'll just have to get used to this platform.... the loop is outside so that makes me think that in traditional nested code, the event could only be called if I'm already iterating through the loop.   I'm sure I'll get better as time goes on...  thanks kindly for the explanation!  Jim
0 Kudos
Message 6 of 7

As RavensFan said, the loop is to allow the event structure to react more than once. When you create an event structure on the block diagram, the first "event" is a timeout  one. If no value is wired to the upper left corner to define a timeout period it sits static, using very little system resources (as opposed to the way it was done prior to the event structure, with all the controls being polled continuously in a loop, usually with some logic to determine if values had changed, etc.). Then, as he mentions, if an event is detected it is "serviced" and whatever is in that particular "event case" is performed, where upon the event structure goes back to sitting at the timeout case. Now if you need to have other things done while waiting for an event, such as updating front panel indicators or something, a timeout value can be wired to that upper left terminal and "stuff" put into the timeout case. What you don't want in that case are vi's that may be entered and not immediately executed, as they can tie up the event structure waiting for the return from the vi.



Message Edited by LV_Pro on 02-24-2010 06:07 PM
Certified LabVIEW Developer

Senior Test Engineer North Shore Technology, Inc.
Currently using LV 2012-LabVIEW 2018, RT8.5

LabVIEW Champion

0 Kudos
Message 7 of 7