01-18-2006 03:12 PM
Hi, I tried using the code u sent me...after doing a few changes (typo's) i wasnt able to see any error even though file_handle = -1. it never satisfies the if statement...
Fmt (filename, "Data_%s_%s.log", DateStr(), TimeStr());
DisableBreakOnLibraryErrors();
file_handle = OpenFile (filename, VAL_READ_WRITE, VAL_TRUNCATE, //when i check filename..it says Data_01/18/2006_16:10:35
VAL_BINARY);
EnableBreakOnLibraryErrors();
if (file_handle == -1 && (error == GetFmtIOError())) //never true
MessagePopup ("Error", GetFmtIOErrorString(error));
I read the help on Open file....and i paid attention to the caution but in my program i need formatio.h.....cant exclude that.
Do you know what other reason it could be? Using the above code....the code runs without errors....but doesnt create the Data log file....
Looking forward for your reply.
Thanks
k1_ke
01-19-2006 03:05 AM
Hello k1_ke,
Now I realize what went wrong. The function TimeStr() returns the time in the format "hh:mm:ss". The problem is that a filename can not contain the character ':'. The following code gets around this problem.
int error_nr;
int hours;
int minutes;
int seconds;
int year;
int month;
int day;
if(file_sel==0)
{ //if file not selected, saves to data.log by default.
file_sel=1;
file_opened=1;
GetSystemDate (&month, &day, &year);
GetSystemTime (&hours, &minutes, &seconds);
Fmt (filename, "Data_%i%i[w2p0]%i[w2p0]_%i[w2p0]%i[w2p0]%i[w2p0].log",year, month, day, hours, minutes, seconds);
DisableBreakOnLibraryErrors();
file_handle = OpenFile (filename, VAL_READ_WRITE, VAL_TRUNCATE,
VAL_BINARY);
EnableBreakOnLibraryErrors();
if (file_handle == -1 && (error_nr = GetFmtIOError()))
MessagePopup ("Error", GetFmtIOErrorString(error_nr));
}
I hope I finally helped you out ![]()
01-19-2006 03:07 AM
01-23-2006 08:12 AM
01-23-2006 08:15 AM