From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
10-12-2015 05:23 AM
Hi guys.
I have developed a VI which connects to database reads table names, the columns of the selected table etc. It works well as I want.
However, I have problem with identifying the UDL file with "File Dialog" function using it in an event structure which is triggered when the "Open" button's value changes. It also works well, when I choose the UDL file, but the problem is when I cancel it and I get error 43.
I tried to manage this problem with an "error handler" function to clear Error 43 but the next errors which are related to the database conncetion are appeared. The reason is, when the File Dialog is cancelled, an empty path goes through connection reference and I cannot prevent starting the while loop where the main codes are. I also used a Case Structure connected to "Cancelled" with "DB Tool Close Connection" in True case and connecting the the connection reference to the While loop, but still I get the same result.
I want to make the application working like: at startup with pushing "Open" button and selecting the UDL file, the while loop run with establishing the database connections, otherwise with cancelling the File Dialog, the application waits for pushing the Open button and selecting the UDL file again.
Thanks a lot for your helps in advance.
Solved! Go to Solution.
10-12-2015 05:38 AM - edited 10-12-2015 05:39 AM
Hi lman,
at startup with pushing "Open" button and selecting the UDL file, the while loop run with establishing the database connections, otherwise with cancelling the File Dialog, the application waits for pushing the Open button and selecting the UDL file again.
Some pseudocode, easy to implement:
WHILE onevent(OPEN button) FileDialog IF file selected THEN open database do calculations ELSE do nothing ENDIF WEND
What's your problem with using loops and case structures?
10-12-2015 05:47 AM
Thanks Gerdw for reply.
Actually, my problem is implementing "else do nothing" part 😄 Apparently, it automatically sends empty path to the Connection reference which starts the while loop, where the calculation codes are there. So, I get further errors e.g error 1, which occurs when it cannot connect to any DB and cannot find any tables etc.
How can I prevent this by implementing "do nothing" part of your pseudocode?
10-12-2015 05:55 AM
10-12-2015 06:21 AM
Hi GerdW
I know how case structure works. As I already mentioned, I used a Case Structure connected to "Cancelled" with "DB Tool Close Connection" in True case to close the connection before the conection reference goes to the while loop but it didn't work.
10-12-2015 06:33 AM
10-12-2015 08:21 AM
In the atachment you can find the VI.
Sorry for forgetting the VI attachment.
10-12-2015 08:28 AM - edited 10-12-2015 08:34 AM
Hi lman,
there is no Case structure, atleast not in the place where it is needed.
And there is no while loop to have your VI request the "Open button" again.
Please try to incorporate the pseudocode I gave you according to the logic you described before!
- And while you are reworking your VI you could remove the local variables and RACE conditions…
- To enhance code readability you should always use UnbundleByName instead of Unbundle!
- Why do you open the database in the event structure, when the user has cancelled the file dialog?
- Why do you open the (very same) database two times?
- Why don't you use error clusters with all functions, which support them?
- Please rethink your overall VI design: with proper event structure usage you could greatly reduce BD size. Setting control properties in each iteration of your loop isn't needed at all…
10-12-2015 09:46 AM - edited 10-12-2015 09:53 AM
Hi GerdW
Thanks a lot for your comments and tips. Actually, I have been using LabView for a few months, and I am still a beginner.
I understood that problem could be from the while loop which is missing around file dialog and also the Open DB connection block which should be out of the event structure.
- I used local variables to keep the block diagram clean with as less wires as possible. I am not sure if it causes Race condition because I couldn't find any miscalculation while it is running.
- It was a mistake to open two same connections. I omitted one of them using connection reference of the other one. (good point. same as undbundlebyName)
Do you have any further tips or comments as I still couldn't find any solutions for it?
10-12-2015 09:53 AM
Hi lman,
Do you have any further tips or comments as I still couldn't find any solutions for it.
Yes!
I used local variables to keep the block diagram clean with as less wires as possible.
THINK DATAFLOW!
Using local variables creates mess. Using wires cleans up a BD!
I am not sure if it causes Race condition because I couldn't find any miscalculation while it is running.
RaceConditions can raise their head when you don't expect them…