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.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Canceling the "File Dialog" and handling the errors caused by the empty path which establishes DB connection

Solved!
Go to solution

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. 

0 Kudos
Message 1 of 18
(3,507 Views)
Solution
Accepted by topic author Iman1988

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?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 18
(3,494 Views)

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? 

0 Kudos
Message 3 of 18
(3,486 Views)

Hi lman,

 

IF-THEN-ELSE is a case structure with just two case (aka default one).

You only need to place the case structure in a suitable way!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 18
(3,478 Views)

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.

0 Kudos
Message 5 of 18
(3,465 Views)

Hi lman,

 

then you didn't use the case structure in the correct way!

 

What have you tried so far? Mind to attach your VI (with the case structure)?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 18
(3,454 Views)

In the atachment you can find the VI. 

 

Sorry for forgetting the VI attachment.

0 Kudos
Message 7 of 18
(3,422 Views)

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…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 18
(3,417 Views)

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?

 

 

0 Kudos
Message 9 of 18
(3,388 Views)

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…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 10 of 18
(3,378 Views)