Jim,
I have seen you contribute on many discussions during my research and troubleshooting. I am truly honored to have you contribute to my discussion here.
At first I had some problems while running the script. After looking through the log and debugger I found that it was stopping on a certain file. The next file was a test file I had formatted differently. I removed that file, didn't change the script and it worked beautifully. I later had a file open when running the script and received another error, but that was an easy fix (close the file).
I intend to understand the entirety of your code, but I have a few further customizations I hope you could also help with:
- Possible to add LSL value to graph and even move to the same side (right) as UCL/LCL?
- Some data sets have a LSL of 50+. This doesn't fit on current graph so I modified the range to 1 - 100. Is there a way to take the pull force requirement and use that to +/- 10 or 20 for the range?
- Some excel sheets are empty. Is there a way to omit graphs?
Edit: I took some time today to add the customizations above and here is the modified code for the above. Looks like it is quite hard to change the reference label. Only hint I found was to make a new text box and use that code, not sure how to link the Y heigh of the reference line though.
Names Default To Here( 1 );
// Delete the old Dashboard
Try( NW << close window );
dirpath = Pick Directory();
TheFileList = Files In Directory( dirpath );
// Create the Dashboard window to place the charts into
NW = New Window( "Asset Dashboard", <<journal, VLB = V List Box() );
// Loop across all of the files found
For( i = 1, i <= N Items( TheFileList ), i++,
dt = Open( dirpath || "\" || TheFileList[i], worksheet( "Sheet1" ), invisible );
// Format data table
dt << Delete rows( 1 :: 13 );
var = dt:column 11[2];
dt:column 11[8] = var; //data
var = dt:column 11[1];
dt:column 11[7] = var; //heading
var = dt:column 3[1];
dt:column 12[7] = var; //heading
var = dt:column 3[2];
dt:column 12[8] = var; //asset #
dt << delete rows( 1 :: 6 );
dt << delete columns( 1, 3, 5, 7, 9, 13 :: 25 );
// Set first row to headers and delete
colNames = dt << get column names;
For( ii = 1, ii <= N Items( colNames ), ii++,
Column( ii ) << set name( Column( ii )[1] )
);
dt << delete rows( 1 );
// Continue to next asset if data table is empty
col=Column( Current Data Table(), "Pull Force Reading");
tableVal = col[22];
if (tableVal == "", i++);
// Capture the Force Requirement value and add it to the graph if it is valid
dt:Pull Force Reading << data type( numeric ) << modeling type( continuous );
theForceRequirement = Num( Word( 1, dt:Force Requirement[1], " " ) );
If( Is Missing( theForceRequirement ) == 0,
range = theForceRequirement;
theForceRequirement = ",Add Ref Line(" || Char( theForceRequirement ) || ", \!"Dashed\!", \!"Black\!", \!"LSL\!", 4 )";,
theForceRequirement = " "
);
// Capture the Asset number
If( dt:Name( "Asset#" )[1] == "",
theAsset = "Unknown",
theAsset = dt:Name( "Asset#" )[1]
);
// Generate the code to produce the chart along with the LSL value
theExpr =
"cc = Control Chart(invisible,
Sample Label( :Date ),
Group Size( 2 ),
KSigma( 3 ),
Chart Col( :Pull Force Reading, Individual Measurement(Show Zones( 1 ), Shade Zones( 1 ),Test 1( 1 ), Test 3( 1 ))),
SendToReport(
Dispatch(
{\!"Individual Measurement of Pull Force Reading\!"},
\!"2\!",
ScaleBox,
{Min( if( (range - 20) <= 0 , 0, range - 20) ), Max( range + 20 ), Inc( 2 ), Minor Ticks( 1 )"
|| theForceRequirement ||
" }
),
Dispatch(
{\!"Individual Measurement of Pull Force Reading\!"},
\!"1\!",
ScaleBox,
{Min( 0 ), Max( 50 ), Inc( 8 ), Minor Ticks( 0 )}
),
Dispatch(
{\!"Individual Measurement of Pull Force Reading\!"},
\!"IR Chart of IM\!",
FrameBox,
{Frame Size( 820, 420 )}
),
Dispatch(
{\!"Individual Measurement of Pull Force Reading\!"},
\!"IR Chart of IM\!",
FrameBox( 2 ),
{Frame Size( 65, 405 )}
)
)
);";
// Run the generated code
Eval( Parse( theExpr ) );
// Close the outline box of the output and set the title based upon the asset value
Report( cc )[Outline Box( 1 )] << Close( 1 ) << set title( "Asset# " || theAsset );
// Append the display output to the display window
VLB << Append( Report( cc ) );
// Clean up the environment by closing the display window and the data table
//cc << close window;
//Close( dt, nosave );
); // End of For Loop