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?
Solved! Go to Solution.
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.
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.
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.
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.