Appendix
E: Sample Script |
|
'sample.vbs |
'20030227TM
BBL modified to use sample_template.xls |
|
'Defining
variables used in executing runs |
dim
blank_criteria |
dim
blanks(8) |
|
blank_criteria
= 100 |
counterchannel=1 |
|
'Defining
variables used in transferring data to excel worksheet |
dim
xcol |
dim
xrow |
dim
xlw |
dim
xls |
dim
xls_file_name |
dim
xls_template |
dim
xla |
dim
sample_counter |
dim
sample_name |
dim
base_row |
dim
base_col |
|
xls_template
= "sample_template.xls" |
|
set
xlw = nothing |
set
xls = nothing |
|
xrow
= 1 |
|
set
xla = CreateObject("excel.application") |
|
'Getting
user input on blank criteria |
do |
|
blank_criteria
= InputBox("Enter Blank Criterion
(0.5um)","Blank Criteria",blank_criteria) |
|
loop
until
isnumeric(blank_criteria) |
|
blank_criteria
= cdbl(blank_criteria) |
|
writeline
"Blank criteria is " & blank_criteria &
"um." |
|
'Get
the output file name from the user and setup the file from its
template |
do |
|
'we
are sure you'll love this nifty FileDialog feature |
|
FileDialog.DialogTitle
= "Create/Open sample XLS" |
|
FileDialog.DefaultExt
= "xls" |
|
FileDialog.FileName
= "" |
|
FileDialog.Filter
= "Excel (*.xls)" |
|
FileDialog.ShowSave |
|
xls_file_name
= FileDialog.FileName |
|
if
not
filer.FileExists(xls_file_name) then |
|
|
on
error resume next |
|
filer.CopyFile
"sample_template.xls", xls_file_name,
False |
|
on
error goto 0 |
|
if
not
filer.FileExists(xls_file_name) then |
|
|
msgbox
"Could not create file '"
& xls_file_name & "'" |
|
|
end
if |
|
|
end
if |
|
loop
until
filer.FileExists(xls_file_name) |
|
'open
the output Excel file |
set
xlw = xla.Workbooks.Open(xls_file_name) |
|
'we
only need to deal with one sheet |
Set
xls = xlw.Worksheets("Working") |
|
writeline
"Working with Excel file " & xls_file_name &
"." |
|
sample_counter
= 1 |
|
do |
|
sample_name
= "SAMPLE" & sample_counter |
|
|
|
'position
ourselves to the first sample cells |
|
dim
r |
|
set
r = xls.range(sample_name) |
|
base_row
= r.row |
|
base_col
= r.column |
|
|
|
if
r.value = "" then |
|
|
exit
do 'found starting place |
|
|
end
if |
|
|
|
sample_counter
= sample_counter + 1 'try next sample |
|
loop
while sample_counter <= 5
'look for blank up to 5 samples |
|
if
sample_counter > 5 then |
|
msgbox
"No more sampling required for file '" &
xls_file_name & "'." |
|
|
|
else |
|
'Defining
3 functions for the 3 steps in sample runs, ie, washing
the sensor, getting the blank and running the sample |
|
|
|
AddPlan("wash_plan") |
|
|
|
AddPlan("blank_plan") |
|
|
|
AddPlan("sample_plan") |
|
end
if |
|
'This
function defines the activity in washing the sensor |
|
function
wash_plan() |
|
wash_plan
= ShowMessage("Press Next to start
washing...","Washing for " &
sample_name) |
|
'Wait
for user prompt |
|
|
|
if
wash_plan = StepNext then |
|
|
Status
= "Rinsing Sensor..." |
|
volume
= 25 |
|
'Flush
sensor |
|
wash
2 |
|
Status
= "Running" |
|
|
end
if |
|
end
function |
|
'This
function defines the activity in obtaining the blank |
function
blank_plan() |
|
blank_plan
= ShowMessage("Press Next to start
blanking...","Blanking for " &
sample_name) |
|
'Wait
for user prompt |
|
if
blank_plan = StepNext then |
|
|
Status
= "Flushing sensor" |
|
volume
= 10 |
|
blank
1,1 |
|
'Flush
sensor for 10ml |
|
|
|
Status
= "Test Run Blank" |
|
volume
= 10 |
|
'Run
blank for 10ml |
|
blank
1,1 |
|
Status
= "Running" |
|
|
end
if |
|
|
'If
blank is expected to exceed criterion |
|
if
Ch(0) * 5 > blank_criteria then |
|
|
blank_plan
= ShowMessage("Blank Expected To
Exceed Criterion. To Proceed Press Next.
To Return to Wash Press Prev",
"Warning! For " &
sample_name) |
|
|
|
if
blank_plan = StepPrev then |
|
|
|
elseif
blank_plan = StepNext then |
|
|
|
end
if |
|
|
end
if |
|
|
|
'obtain
counts at all bin size channel b2-1 to b2-8 |
|
|
|
Status
= "Run blank for 50ml, then 50ml..." |
|
|
volume
= 50 |
|
blank
1,2 |
|
Status
= "Running" |
|
|
dim
i |
|
|
|
for
i = 0 to 7 |
|
|
blanks(i)
= (Ch(i) + PrevCh(i))/2.0 |
|
'compute
average of b1-x and b2-x, for x 1 to 8,
as bAve-1 to bAve-8 |
|
|
next |
|
|
|
'If
blank exceeded criterion |
|
if
blanks(1) > blank_criteria then |
|
|
blank_plan
= ShowMessage("Blank exceeded
criterion. To proceed anyway press Next.
To return to Wash Sensor press Prev",
"Warning! For " &
sample_name) |
|
|
|
if
blank_plan = StepPrev then |
|
|
|
elseif
blank_plan = StepNext then |
|
end
if |
|
|
end
if |
|
|
end
function |
|
function
sample_plan() |
'Run
Routine |
|
dim
samples1(8) |
|
dim
samples2(8) |
|
dim
samples3(8) |
|
dim
sample1name |
|
dim
sample2name |
|
|
|
sample_plan
= ShowMessage("Press Next to start
sampling...","Sampling for " &
sample_name) |
|
if
sample_plan = StepNext then |
|
|
sample1name
= "Sample12" |
|
sample2name
= "Sample34" |
|
|
|
Status
= "Priming sensor..." |
|
volume
= 10 |
|
'Flush
sensor for 10ml |
|
'Run
sample for 50ml |
|
'obtain
counts at all bin size channel s1-1 to s1-8 |
|
'run
sample for another 50ml |
|
'obtain
counts at all bin size channel s2-1 to s2-8 |
|
'compute
average of s1-x and s2-x, for x 1 to 8, as
sAve(1&2)-1 to sAve(1&2)-8 |
|
|
|
Status
= "Run sample 1,2 for 50ml, then
50ml..." |
|
volume
= 50 |
|
blank
1,2 |
|
|
|
dim
i |
|
for
i = 0 to 7 |
|
|
samples1(i)
= (Ch(i) + PrevCh(i))/2.0 |
|
|
next |
|
|
|
'Run
sample for another 50ml |
|
'obtain
counts at all bin size channel s3-1 to s3-8 |
|
'run
sample for another 50ml |
|
'obtain
counts at all bin size channel s4-1 to s4-8 |
|
'compute
average of s3-x and s4-x, for x 1 to 8, as
sAve(3&4)-1 to sAve(3&4)-8 |
|
|
|
Status
= "Run sample 3,4 for 50ml, then
50ml..." |
|
volume
= 50 |
|
blank
1,2 |
|
Status
= "Running" |
|
|
|
for
i = 0 to 7 |
|
|
samples2(i)
= (Ch(i) + PrevCh(i))/2.0 |
|
|
next |
|
|
|
if
abs(samples1(1) - samples2(1)) /
min(samples1(1),samples2(1)) > 0.1 then |
|
|
'If
(|sAve(1&2)-1 -
sAve(3&4)-1|)/(smaller of
sAve(1&2)-1 sAve(3&4)-1) > |
|
'10%,
abort run, goto "Third Run"
Subroutine |
|
'Third
Run Subroutine |
|
'Run
sample for another 50ml |
|
'obtain
counts at all bin size channel s5-1 to
s5-8 |
|
'run
sample for another 50ml |
|
'obtain
counts at all bin size channel s6-1 to
s6-8 |
|
'compute
average of s5-x and s6-x, for x 1 to 8,
as |
|
'sAve(5&6)-1
to sAve(5&6)-8 |
|
|
|
Status
= "Run sample 5,6 for 50ml, then
50ml..." |
|
volume
= 50 |
|
blank
1,2 |
|
Status
= "Running" |
|
|
|
for
i = 0 to 7 |
|
|
samples3(i)
= (Ch(i) + PrevCh(i))/2.0 |
|
|
next |
|
|
|
dim
compare1 |
|
dim
compare2 |
|
|
|
compare1
= abs(samples1(1) - samples3(1)) /
min(samples1(1),samples3(1)) |
|
compare2
= abs(samples3(1) - samples2(1)) /
min(samples3(1),samples2(1)) |
|
|
|
if
compare1 > 0.1 and compare2 > 0.1
then |
|
|
'if
this average does not meet the
10% requirement with |
|
'either
set, prompt user for rerun or
end |
|
|
|
dim
m |
|
|
|
m
= msgbox("Press OK to
rerun, Cancel to
End",vbOKCancel) |
|
|
|
if
m = vbOK then |
|
|
|
else |
|
|
|
end
if |
|
|
|
exit
function |
|
|
else |
|
|
if
abs(samples1(1) - samples3(1))
< abs(samples3(1) -
samples2(1)) then |
|
|
'if
this average is closer
to the first set of
average and |
|
'meets
the 10% requirement, use
this set to replace run
3 and 4 |
|
|
|
for
i = 0 to 7 |
|
|
samples2(i)
= samples3(i) |
|
|
next |
|
|
|
sample2name
= "Sample56" |
else |
|
'if
this average is closer
to the 2nd set of
average and |
|
'meets
the 10% requirement, use
this set to replace run
3 and 4, and set 3 |
|
'and
4 to replace set 1 and
2. |
|
|
|
for
i = 0 to 7 |
|
|
samples1(i)
= samples3(i) |
|
|
next |
|
|
|
sample1name
= "Sample56" |
end
if |
|
|
|
|
|
|
end
if |
|
|
|
'else
transfer all data to excel file. |
|
|
|
for
i = 0 to 7 |
|
|
xls.cells(base_row
+ i,base_col) = blanks(i) |
|
xls.cells(base_row
+ i,base_col + 1) = samples2(i) |
|
writeline
"Blank(" & i & ")
= " & blanks(i) |
|
writeline
"Sample(" & i &
") = " & samples2(i) |
next |
|
|
|
sample_counter
= sample_counter + 1 |
|
|
|
if
sample_counter <= 5 then |
|
|
xlw.save
'just in case |
|
|
|
writeline
"Saved Excel file for " &
sample_name |
|
|
|
sample_name
= "SAMPLE" &
sample_counter |
|
|
|
dim
r |
|
set
r = xls.range(sample_name) |
|
base_row
= r.row |
|
base_col
= r.column |
|
|
|
sample_plan
= StepJump("wash_plan") |
else |
|
set
xls = nothing |
|
|
|
if
not xlw
is
nothing then |
|
|
xlw.save |
|
xlw.close |
|
writeline
"Saved and closed Excel
file for " &
sample_name |
|
set
xlw = nothing |
|
|
end
if |
|
|
|
sample_plan
= StepEnd |
|
|
|
|
end
function |
|
sub
onterminate() |
|
'close
files here, if necessary |
|
'xls.parent.close
true |
|
|
|
set
r = nothing |
|
set
xls = nothing |
|
if
not xlw
is nothing
then |
|
|
xlw.save |
|
xlw.close |
|
set
xlw = nothing |
end
if |
xla.quit |
set
xla = nothing |
|
|
end
sub |
|