I have written some code that tests our CAM software.
The main test we run takes over 48 hours on 1 PC.
I am breaking that down into logcal groups and running on VM's so that the total time is about 2 hours!
(Macro Scheduler sets the parameters for each group and then launches a 3rd party test tool.)
My problem is that when the tests are completed, I would like to have each group write their results to a combined csv file.
Group 1 needs to be lines 1 - 500
Group 2 needs to lines 501 - 1000, etc.
Of course each group doesn't finish at the same time.
I am trying to do this... (psuedo code)
(each group would run this and wait until files was not locked)
While datafile is locked - Wait
When datafile is not locked:
Lock datafile
Read datafile (18000 lines) (CSVFileToArray)
Read results for this group of tests
Replace datafile lines for this group with current data
Write new datafile
My problem is how to lock the datafile long enough to swap the data the current results.
OR
Is there a better approach to take?
Writing to file - Design help needed
Moderators: JRL, Dorian (MJT support)
-
- Macro Veteran
- Posts: 267
- Joined: Mon Sep 27, 2010 8:57 pm
- Location: Seattle, WA
Re: Writing to file - Design help needed
AFAIK you'd need to use VBScript to lock the file by creating a File System Object then Killing the File System Object when you want the file available. Macro Scheduler's WriteLn> function locks a file for the fraction of a second it takes to write to the file and then releases the file. So it is not a viable method to lock files for extended periods.
If I were doing this, I think I would instead just create multiple temporary files then at the close of the program merge the temp files together perhaps using a completely separate script that runs when all the others are complete. Finally, of course, delete or perhaps archive the temp files. If you were trying to interweave the data together:
From Group 1
From Group 2
From Group 1
From Group 2
etc.
I could see trying to control access. But since you are lumping the data groups together the simple thing would be write to separate files then merge the files. Actually, even if you were interveaving the data I'd still write separate files then read one line at a time from each of the temp files consecutively and write those lines to the main file as they are acquired.
If I were doing this, I think I would instead just create multiple temporary files then at the close of the program merge the temp files together perhaps using a completely separate script that runs when all the others are complete. Finally, of course, delete or perhaps archive the temp files. If you were trying to interweave the data together:
From Group 1
From Group 2
From Group 1
From Group 2
etc.
I could see trying to control access. But since you are lumping the data groups together the simple thing would be write to separate files then merge the files. Actually, even if you were interveaving the data I'd still write separate files then read one line at a time from each of the temp files consecutively and write those lines to the main file as they are acquired.
-
- Macro Veteran
- Posts: 267
- Joined: Mon Sep 27, 2010 8:57 pm
- Location: Seattle, WA
Re: Writing to file - Design help needed
Thanks JRL
That is one approach and would make life much easier.
The end user wants data updates as available but I may just tell them to wait.
After all we are going from 48 hrs to 2!
I was hoping I was missing an easy solution.
That is one approach and would make life much easier.
The end user wants data updates as available but I may just tell them to wait.
After all we are going from 48 hrs to 2!
I was hoping I was missing an easy solution.