04-25-2012 07:48 AM
Hello
I got a problem with creating a new file when I start running my code. I set it to be "open or create". As I read in the context help, when there is no file in the file path, it should create a new automatically but it didn't. When I deleted the file in file path on the front panel, error 1 occured. There is no problem with "open" when the file exists.
I want my vi to create a new file every time I start running my code and save it, then recreate another file in the next run.
Thanks!
Solved! Go to Solution.
04-25-2012 07:57 AM
I think you may be misunderstanding the default value for File Open/Create.
If you wire a control to the File Open, it will use the value of the control regardless of whether that value is empty or valid.
If you don't wire anything to the File Path input of File Open, then it will open a dialog.
For your case, you may want to do some checking on the control path validity before doing the file open.
Why not put the File Open logic in your Event structure?
Your architecture as it stands is a bit odd. You have an event loop but exit of your event loop is a prerequisite to running the rest of your program.
Also, you likely don't need any of those local variables.
04-25-2012 08:03 AM
Hi,
I couldn't run your code as some VIs were missing. Anyway, Try the attached example. It may help you. What is the error that you are getting?
Regards,
Nitz
(Give Kudos to Good Answers, Mark it as a Solution if your problem is Solved)
04-25-2012 08:06 AM
more subvi
04-25-2012 08:08 AM
04-25-2012 08:39 AM
@ Taki1999
How to do the checking on the control path?
Could you please make some changes on my vi? I am so confused now.
The reason I have the event loop as a prerequisite before the main loop is running is about user interface. I want the user to adjust everything before running. Im not sure if it's a good idea but it has been working correctly as I want so far.
04-25-2012 09:28 AM
@Bombbooo wrote:
@ Taki1999
How to do the checking on the control path?
Use Is Empty String/Path? from the Comparisons Palette. You might also consider using the File Dialog from the FileIO Palette->Advanced.
Could you please make some changes on my vi? I am so confused now.
I'll give it a look. I recommend you start using LabVIEW projects and then create zip files.
The reason I have the event loop as a prerequisite before the main loop is running is about user interface. I want the user to adjust everything before running. Im not sure if it's a good idea but it has been working correctly as I want so far.
I'm guessing there's a better architecture. Your current setup will require you to restart the program on every run. I think a more natural behavior would allow the user to keep the program open and just hit the run button again. Look into a state machine for this.
04-25-2012 09:45 AM
I made some comments on your vi.
Additionally, you may want to start reading up on State Machines.
04-25-2012 09:47 AM
can you save it in 2010 version? Thanks
04-25-2012 09:50 AM
@Bombbooo wrote:
can you save it in 2010 version? Thanks
Now in 2010.