LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Choosing a name when saving to a file

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

0 Kudos
Message 11 of 15
(1,268 Views)

  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 Smiley Wink

0 Kudos
Message 12 of 15
(1,261 Views)
Appearantly I posted my reply while you were posting yours. It's above your last post...
0 Kudos
Message 13 of 15
(1,262 Views)
Hi Wim,
 
Thank you very much for your replies. I was away from the office therefore unable to reply earlier. I would just like to inform you that it works perfectly now.
 
I really appreciate your help and if anything comes round will email you again.
 
Once again thank you so much
 
Thanks
 
k1_ke
0 Kudos
Message 14 of 15
(1,245 Views)
No problem Smiley Wink
0 Kudos
Message 15 of 15
(1,240 Views)