Saladsamurai
10-28-2009, 11:07 AM
I have a code that I am working on. It is primitive and inefficient and that is fine with me.
The code loops and each loop it does the following:
1. Writes a .BAT file and stores it the variable "SolverBat"
2. Calls an application using Shell(SolverBat)
The application itself then solves a simulation and writes the data to a file called "Results.csv" This name is the default and cannot be changed.
3. Loops again and thus Overwrites "Results.csv" with new file of same name.
I want to be able to tell when "Results.csv" has been completely written so I can loop through it and collect the results.
Note
It is not enough to just check to see if "Results.csv" exists. It must also be checked (perhaps in a loop of sorts) to make sure it is finished.
Any thoughts?
Sub BatchSolve()
Dim fNum As Long
Dim InstallDir As String
Dim BookPath As String
Dim SolverBat As String
Dim i As Long
For i = 1 To 1
fNum = FreeFile()
InstallDir = "Z:\Casey_B\from Jon\PDML\Test"
BookPath = Workbooks("Test.xls").Path & "\"
SolverBat = BookPath & "Solve.Bat"
Open SolverBat For Output As fNum
Print #fNum, "call" & Chr(34) & "c:\Program Files\MentorMA\flosuite_v82\flovent\WinXP\bin\flovent" & Chr(34) & " -env"
Print #fNum, "echo Start"
Print #fNum, "call" & Chr(34) & "c:\Program Files\MentorMA\flosuite_v82\flovent\WinXP\bin\flovent" & Chr(34) & " -b" _
& " Test" & i & " -O Z:\Casey_B\from Jon\PDML\Test\TestCSV"
Print #fNum, "echo " & i
Close #fNum
Shell (SolverBat)
Start Checking on "Results.csv"
If it exists and finished writing Then
Collect data
Else Check again
Next i
End Sub
Also: I don't undersatnd what freefile is or does? I read the help, but it is vague.
What would happen if I just used some number like #3 or something?
The code loops and each loop it does the following:
1. Writes a .BAT file and stores it the variable "SolverBat"
2. Calls an application using Shell(SolverBat)
The application itself then solves a simulation and writes the data to a file called "Results.csv" This name is the default and cannot be changed.
3. Loops again and thus Overwrites "Results.csv" with new file of same name.
I want to be able to tell when "Results.csv" has been completely written so I can loop through it and collect the results.
Note
It is not enough to just check to see if "Results.csv" exists. It must also be checked (perhaps in a loop of sorts) to make sure it is finished.
Any thoughts?
Sub BatchSolve()
Dim fNum As Long
Dim InstallDir As String
Dim BookPath As String
Dim SolverBat As String
Dim i As Long
For i = 1 To 1
fNum = FreeFile()
InstallDir = "Z:\Casey_B\from Jon\PDML\Test"
BookPath = Workbooks("Test.xls").Path & "\"
SolverBat = BookPath & "Solve.Bat"
Open SolverBat For Output As fNum
Print #fNum, "call" & Chr(34) & "c:\Program Files\MentorMA\flosuite_v82\flovent\WinXP\bin\flovent" & Chr(34) & " -env"
Print #fNum, "echo Start"
Print #fNum, "call" & Chr(34) & "c:\Program Files\MentorMA\flosuite_v82\flovent\WinXP\bin\flovent" & Chr(34) & " -b" _
& " Test" & i & " -O Z:\Casey_B\from Jon\PDML\Test\TestCSV"
Print #fNum, "echo " & i
Close #fNum
Shell (SolverBat)
Start Checking on "Results.csv"
If it exists and finished writing Then
Collect data
Else Check again
Next i
End Sub
Also: I don't undersatnd what freefile is or does? I read the help, but it is vague.
What would happen if I just used some number like #3 or something?