App Developer build in function File

Discuss PC Developer and Web Developer projects and features here.
Post Reply
stefan.erni
Valued Contributor
Posts: 758
http://meble-kuchenne.info.pl
Joined: Wed Dec 02, 2020 10:53 am
Has thanked: 149 times
Been thanked: 171 times

App Developer build in function File

Post by stefan.erni »

Hi Ben

I wrote a testprogram for the build in function File.
It's working fast and with long filename.

Only create with the file and close the file there is a little problem.

So I first have to start the program with creat file and then close the program and switch off createfile when the program second time runs.
I also have to close the app before I can open the file in windows. But the file is written extremely quickly

regards
Stefan

file on windows:
file_2022-09-21_11-23-03.jpg
file_2022-09-21_11-23-03.jpg (5.82 KiB) Viewed 5559 times
Attachments
FC9_HX711_monitor_1.fcsx
(11.63 KiB) Downloaded 313 times

BenR
Matrix Staff
Posts: 1739
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 440 times
Been thanked: 603 times

Re: App Developer build in function File

Post by BenR »

Hi Stefan,

If you first try to open the file, then if this fails you can then create the file. This shuold save you going back and having to remove the create file on the second pass.

Regarding the file being locked while flowcode is open, if you call the close macro then the file should be available as soon as the write is complete.

BenR
Matrix Staff
Posts: 1739
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 440 times
Been thanked: 603 times

Re: App Developer build in function File

Post by BenR »

Aha sorry Steve just pointed out your using the API calls directly and not the file component.

In this case you can call the flush API call to force any pending writes to be completed and then set the file handle to 0 to effectively close the file.

I also didn't add that creating the file will also open the file and so the logic should be like this.

check = FileOpen
if check = false
{
FileCreate
}
Write to file
FileClose

Steve-Matrix
Matrix Staff
Posts: 1253
Joined: Sat Dec 05, 2020 10:32 am
Has thanked: 167 times
Been thanked: 277 times

Re: App Developer build in function File

Post by Steve-Matrix »

Here's an example.
FC9_HX711_monitor_2.fcsx
(13.36 KiB) Downloaded 337 times

stefan.erni
Valued Contributor
Posts: 758
Joined: Wed Dec 02, 2020 10:53 am
Has thanked: 149 times
Been thanked: 171 times

Re: App Developer build in function File

Post by stefan.erni »

Hi Ben, Hi Steve

Thanks a lot.It's working fine now.

With the part "if file not can be open, then create", I understand.

And that there is no command macro for file close so I use file open but with parameter 0 for read and write.
I suppose that's what Ben means.
I will continue to save and open large amounts of data in arrays.

regards
Stefan

to close the file
file_save_2022-09-21_13-38-38.jpg
file_save_2022-09-21_13-38-38.jpg (42.37 KiB) Viewed 5543 times

Steve-Matrix
Matrix Staff
Posts: 1253
Joined: Sat Dec 05, 2020 10:32 am
Has thanked: 167 times
Been thanked: 277 times

Re: App Developer build in function File

Post by Steve-Matrix »

stefan.erni wrote:
Wed Sep 21, 2022 12:59 pm
And that there is no command macro for file close so I use file open but with parameter 0 for read and write.
Use the "flush" API call to close the file for reading/writing as in the example.

stefan.erni
Valued Contributor
Posts: 758
Joined: Wed Dec 02, 2020 10:53 am
Has thanked: 149 times
Been thanked: 171 times

Re: App Developer build in function File

Post by stefan.erni »

Hi Steve

If I use the example with the flush I get this message. So I have to close FC and then I can open the file.
I don't know exactly what I'm doing wrong that it doesn't work for me on my computer.

regards

Stefan
notopen_2022-09-21_15-11-12.jpg
notopen_2022-09-21_15-11-12.jpg (14.87 KiB) Viewed 5539 times

stefan.erni
Valued Contributor
Posts: 758
Joined: Wed Dec 02, 2020 10:53 am
Has thanked: 149 times
Been thanked: 171 times

Re: App Developer build in function File

Post by stefan.erni »

Hi Steve

Now it's working nice to close the file.

As you wrote flush and open with 0,0,0

regards

Stefan
Attachments
Snag_6e7ebe.png
Snag_6e7ebe.png (24.4 KiB) Viewed 5188 times

Post Reply