Logging File Name


kmatthews

Recommended Posts

i am currently logging data to a cvs file on our server and naming it a different name every day, that being the date and time when i make this occur. i have a problem when i have to restart the application and starts using the file name that was last saved until the time comes to rename file. this happens every morning at 8 o'clock. is there a way to name file the first time through to the correct date and time for the present day? im using daqfactory express and this string to name file.

while(1)
   if (Systime() > 8h00m)
	  delay(30)
	  if (Systime() < 8h01m)
	 Logging..NonWoven_Logging.strFileName = "s:\runtime_logging\NonWoven_" + FormatDateTime("%y_%m_%d_%H%M.csv",SysTime())
	 endif
   delay(30)
   endif

Link to comment
Share on other sites

First, as you can see, you are missing an endwhile. I'll assume you just forgot to paste it.

Now on to the question at hand. Your logic in the script is a little complex. Plus, I think you mean, name the file to the present day if it is > 8am, but name it to yesterday if it is < 8am. This will probably work better:

while(1)

Logging..NonWoven_Logging.strFileName = "s:\runtime_logging\NonWoven_" + FormatDateTime("%y_%m_%d_8_0.csv",SysTime()-28800)

delay(30)

endwhile

There is no reason to have the %H%M in there because you want it to name the file at 8am, so it will always be _8_0. I hard coded it, or you could just exclude it. This makes it so we can use the normal trick for changing the name at the end of the day. We simply repeatedly name the file based on the time, but since the day, month and year only change once a day, the command does the exact same thing 99.9% of the time, then at the end of the day, it switches over. Normally, we'd just have systime() in there, which would cause the name change to occur at midnight, but you want it to occur at 8am. Before 8am, it should be named yesterday's date, so all we do is shift the time by 8 hours or 28800 seconds.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.