LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

what does closefile do ? (funny-function?)

Hi I have some trouble with the closefile function :

FILE = OpenFile (dir, VAL_WRITE_ONLY, VAL_APPEND, VAL_ASCII);

mylog(FILE);//pass file handling to mylog function
//mylog writes stuff in the file of course

Status = CloseFile(FILE);//Status==0

//now!
mylog function still can write in the file with the file handle that passed before... but should it be nonvalid now ?

thanks !
0 Kudos
Message 1 of 9
(3,023 Views)
SRQ: 198910

Hello,

i tried several ways to reproduce what you describe.
i always get an runtime error which tells me, that the file handle is not valid any longer after i use the CloseFile() function.
in which context do you use the function which writes your data?

in basic the handle should be no longer valid after you use the CloseFile() function

regards,
Robert H.
National Instruments
0 Kudos
Message 2 of 9
(3,023 Views)
Hi Robert,

I have create a Log function to reports all error and warning from an instrument. The user can always disable or enable the log function ... and so I was trying to check if the user pass a valid file id, to make the log function valid or not.
In the log function I save the File id in a global variable...but once I pass a valid file id and i dont overrite the log_file_id i will be able to write still in log file...

I use CVI7.0 on XP. Ideas ? Thanks !
0 Kudos
Message 3 of 9
(3,023 Views)
Hello,

i tried also to save the handle in a global variable; with the same result, after i called CloseFile() i got a runtime error "Bad file handle";
can you attach a example of your code, that i can see, where you save the variable?

regards,
Robert H.
National Instruments
0 Kudos
Message 4 of 9
(3,023 Views)
Hello,

Ok I attach the file...

1.Right Double Click to start
2.EnableLog
3.Write to file
4.ClosePanel (do close file handle)
5.Start Panel again (right double click)
6.Write to file (still works !)

now Im wondering ? thanks a lot
0 Kudos
Message 5 of 9
(3,023 Views)
hello,

now i can follow the problem:
you put the file handle into your variable, but when you close it, you don't invalidate your global.
if you insert your function call "PUBLIC_NWALog();" with a 0 as a parameter:
PUBLIC_NWALog(0);
you can invalidate your global.
you can test the other way round:
if you once called the function and closed your panel, rename the file you write to.
if you call the write function again it will create the file again. this is because you have the handle still in your global variable.

hope this helps,

Robert H.
National Instruments
0 Kudos
Message 6 of 9
(3,023 Views)
Hi Robert again,

-The CloseFile function dont change the value of the file handle variable - right ?

-So I dont need to invalidate my global - right ?

Would be very happy on an answer on this 🙂 thanks
0 Kudos
Message 7 of 9
(3,023 Views)
hello,
the CloseFile function invalidates the handle;
but the value remains in your global; so you have a invalid handle in your variable;
if you use that, it may function but may also not, it's not assured.
so it's better to open for each access to the file a handle with open and discard it with close

regards,
Robert Halas
National Instruments
0 Kudos
Message 8 of 9
(3,023 Views)
thanks robert i got it.
0 Kudos
Message 9 of 9
(3,023 Views)