05-16-2019 01:29 AM
@altenbach wrote:
OTOH, a huge diagram acts like a parachute. 😄
Can make you feel safe, but requires skill to operate properly and probably better avoided in all but emergencies?
05-16-2019 02:57 AM
@cbutcher wrote:
@paul_cardinale wrote:
I though Galileo debunked that idea,
Somebody's never dropped a feather and a brick outside of a vacuum...
That's why when making a "one liner", you should always leave lots of empty space between everything, covering at least 6 screen: to change the surface/mass ratio.
05-16-2019 03:50 AM
hi ,
thank You everyone .
my probleme is when i add Event Structure to the While Loop to stop the execution when i close the front panel window . the program is running to slow . i want to know why ? and how i solve the probleme ?
i didn't face the probleme when i use only a button to stop the While Loop .
Database table :
if you like my code (Kudos are Welcome ).
05-16-2019 04:05 AM
The event structure will wait until it receives an event. So the other code will run and then nothing will happen until an event occurs that the event structure handles.
Put the "search" code inside an event for that button's Value changed event together with the ID index-search code. And that DB code that gets the IDs, do you really need that in the loop or just once before the loop? If you need to update it, then either do it in the event timeout or using a button and event for it. And now you will have no code left outside the event structure and everything will work.
05-16-2019 04:11 AM
The event structure will stall the while loop until an event happens.
A quick and dirty fix would be to add a time out to the event structure (a number to the Event Timeout, default is -1, never time out). That will probably cause other problems, as the event executes first thing, and then does noting until the next cycle...
You're mixing techniques here (pooling here, events there), and that works really poorly.
The loop on the left polls the string. This will, BTW, bring one CPU to it's knees. At least put a wait in there. Even better, use the event structure for it!
So, the event structure will also wait for a value change on the string, then do the "changed string" stuff. E.g. execute the DB queries. The other events can stay as they are.
05-16-2019 06:46 AM - edited 05-16-2019 06:47 AM
A few questions/comments:
1. Does the code to populate the ID strings need to run every time or just when you start the program?
2. There are no guarantees that the ID strings will be populated before you read them for your search. This could lead to unpredictable results.
3. Your search loop can be replaced with Search 1D Array from the array pallette.
4. As has already been noted you should put a timeout on the event structure. Alternately you could put the other code in a separate loop. I have attached a vi showing what that might look like. I assumed that the code to populate the ID strings only needs to run once.
5. I added a small wait inside the case structure. The CPU will run wide open most of the time without the wait.
6. I would also consider using a queued message handler approach so that the Search button could be an event instead of polled.
05-16-2019 06:52 AM
7. Don't call your VI "Untitled n.vi" (n being a number).
05-16-2019 06:55 AM
05-16-2019 07:05 AM
@johntrich1971 wrote:
wiebe@CARYA wrote:
7. Don't call your VI "Untitled n.vi" (n being a number).
Agreed. 🙂
It won't make the VI run faster, but might very well speed up development.
05-16-2019 10:37 AM - edited 05-16-2019 11:01 AM
So, this has nothing to with speed after all, just with temporary deadlocks due to poor programming.
OK, you need one while loop and one event structure with two or three event cases:
How often does the database change? (1) Either it does not change, then you need to read the IDs only once or (2) I can change, then the index of the IDs may no longer correspond tot he entries you read later inside the case structure. The database seems quite small. Couldn't you real all fields (ID, Name, brand, etc) once before the loop and place into a 2D string array and the ID in the selector (I would prefer a ring instead of a combobox!) Do an event for the ring value change and use the value directly to index into the string array.
Do you really need to find all IDs with every iteration of the loop?