01-24-2019 03:19 PM
I started this conversation in another thread but this is not the same topic, so here's the new question. I was told that I was using too many local variable but I don't know how to get rid of them. Here's the updated code with some other fixes. This code works great butif I'm doing something wrong I'd like to fix it.
01-24-2019 03:50 PM
For some things it is OK to use local variables, like if you only care about the most recent value in a control and it is ok to miss some of the values in between. But, other times when the expected value and the actual value are different you have a race condition. And when the expected value and actual value are only sometimes different you have a race condition that is hard to track down.
It is also a little awkward to have an event structure side-by-side those case structures which are triggered by booleans. The event structure is very good at detecting a boolean value change, so you should put those inside the event structure, and then you not have to make the event structure timeout every 100ms. Also, make some SubVIs that perform a well-defined function, like taking your instrument measurement. Then your code can fit on one screen and you won't have to use the stacked sequence structure.
01-24-2019 04:14 PM
I would restructure this as a Queued Message Handler:
Two parallel loops:
One with an event handler, generating messages,
the other processing the messages.
Store data in shift registers.
Inside your event structure, there is a sequence frame; it's doing nothing, get rid of it.
The 2 local variables for "Sheet Name to load" & "Excel Setup File" are unnecessary because you have the control terminals right there; use them.
01-24-2019 04:21 PM
OK so you added a toplevel while loop. Good!
(You don't need to wire indices of "index array" if you want to get the elements in order)
Now for the cleanup:
01-24-2019 08:54 PM - edited 01-24-2019 08:55 PM
@altenbach wrote:
OK so you added a toplevel while loop. Good!
(You don't need to wire indices of "index array" if you want to get the elements in order)
Yes. I have no idea why the OP decided to put all those in when my example to him eliminated almost all of them!
01-25-2019 08:09 AM
Good morning guys. I'm reading your posts and trying to implement your suggestions. Thank you very much for helping me BTW.
I got rid of the unused flat sequence and added the undo into the event structure. Turning portions of this into sub vi's is next unless you see something else. In the stacked structure I want to change the 1[0..2] portion into a subvi. The issue is with that local variable. How can I accomplish this? I have all day to work on this so I'd appreciate it if you could try to walk me through this a step at a time until it looks and work on a professional level. Let's go!
01-25-2019 08:16 AM
If you are basing it on a local variable of the current diagram, when you create the subVI, the value from the local variable (or terminal, or wire from somewhere else in the code) will pass into the subVI via the connector panel.
If the local variable is included in the selection window when you highlight the code and pick Edit >> Create subVI, you'll see it turns it into a reference of that boolean control, and places an explicit value property node inside the subVI.
Instead, if you move the local variable to a position so it is not included in the region you select, basically the boundary of the selection region crosses over the wire coming from the local variable, you'll see it creates a control in the subVI that is put on the connector panel and the local variable in your main VI will attach to that connector in the new subVI.
01-25-2019 09:42 AM
Thanks. That's what I did. Here's where I'm at after making some sub vi's.
01-25-2019 10:13 AM - edited 01-25-2019 10:15 AM
If you must use the RGT to retrieve values from an XLS file, set the datatype on the Excel Get Data to be an array of doubles. No post-import conversion would be required on your part.
Why convert the number of supplies to a string in order to do a select? Instead do something a little bit smarter that doesn't require a select statement at all.
01-25-2019 10:36 AM
@RHutchings wrote:
Thanks. That's what I did. Here's where I'm at after making some sub vi's.
I don't see where yo made any subVI's.
Where do you want to make subVI's?