cs168
08-11-2005, 03:56 PM
Hi I am new in ASP programming so I do use the very basic and simple way to do all my stuff. Now I do really got stuck at how can I loop thru the calculation for all my selection.. My full code is as below:-
<%
tBegin = request("beginww")
tEnd = request("endww")
tPkg = request("pkgtype")
tYear = request("wwyear")
%>
<body>
<form name= "frmbrowsepkg" method="POST">
Year: <select name="wwyear" id="wwyear">
<%if tYear = "" then tYear = Year(date)
for t = 2005 to tYear%>
<option value="<%=t%>" <%if t = cint(tYear) then%>selected<%end if%>><%=t%></option>
<%next%>
</select>
Start Week: <select name="beginww" id="beginww">
<% if tBegin = "" then tBegin = 1
for t = 1 to 53%>
<option value="<%=t%>" <%if t = cint(tBegin) then%>selected<%end if%>><%=t%></option>
<%next%>
</select>
End Week: <select name="endww" id="endww">
<% if tEnd = "" then tEnd = 1
for t = 1 to 53%>
<option value="<%=t%>" <%if t = cint(tEnd) then%>selected<%end if%>><%=t%></option>
<%next%>
</select>
Package Type:
<select name="pkgtype" id="pkgtype">
<option Value="P">All Pkg
<option value="G"> All Green Pkg
<option Value = "128">PQFP128
<option Value = "208">PQFP208
<option Value = "PK100">PK100
<option Value = "PK128">PK128
<option value="<%=pkgtype%>"Selected</option>
</select>
<INPUT TYPE="submit" runat="server" VALUE="Cal CPK"></INPUT>
</form>
<%
if Request.ServerVariables("REQUEST_METHOD") = "POST" then
%>
<table width="100%" align="center" bgcolor="#0d5692">
<tr>
<td width="7%" align="center" bgcolor="#ffffff"><font face="verdana" size="2"><b>PKG Type</b></font></td>
<td width="5%" align="center" bgcolor="#ffffff"><font face="verdana" size="2"><b>Mean</b></font></td>
<td width="5%" align="center" bgcolor="#ffffff"><font face="verdana" size="2"><b>Average<br>Moving Range</b></font></td>
<td width="7%" align="center" bgcolor="#ffffff"><font face="verdana" size="2"><b>UCL</b></font></td>
<td width="7%" align="center" bgcolor="#ffffff"><font face="verdana" size="2"><b>LCL</b></font></td>
<td width="7%" align="center" bgcolor="#ffffff"><font face="verdana" size="2"><b>Total<br>Record</b></font></td>
<td width="7%" align="center" bgcolor="#ffffff"><font face="verdana" size="2"><b>Range<br>Mean</b></font></td>
<td width="7%" align="center" bgcolor="#ffffff"><font face="verdana" size="2"><b>Range<br>UCL</b></font></td>
<td width="7%" align="center" bgcolor="#ffffff"><font face="verdana" size="2"><b>Range<br>LCL</b></font></td>
<td width="5%" align="center" bgcolor="#ffffff"><font face="verdana" size="2"><b>CPK</b></font></td>
<td width="5%" align="center" bgcolor="#ffffff"><font face="verdana" size="2"><b>CP</b></font></td>
</tr>
<%
SET RS=CreateObject("ADODB.Recordset") 'create a recordset
select case request ("pkgtype")
case "P"
sql="select Avg1, Range1, PkgType from tblFiles where Pkgtype Not Like '%G%' and workweek between " & tBegin & " and " & tEnd & " and Year = " & tYear & " Order by workweek DESC"
Pkgid= "All Sn/Pb Pkg"
case "G"
sql="select Avg1, Range1, PkgType from tblFiles where Pkgtype Like '%G%' and workweek between " & tBegin & " and " & tEnd & " and Year = " & tYear & " Order by workweek DESC"
Pkgid= "All Green Pkg"
case "208"
sql="select Avg1, Range1, PkgType from tblFiles where Pkgtype Like '%208' and Pkgtype Not Like '%G208' and workweek between " & tBegin & " and " & tEnd & " and Year = " & tYear & " Order by workweek DESC"
Pkgid= "PQFP 208"
case "128"
sql="select Avg1, Range1, PkgType from tblFiles where Pkgtype Like '%128' and Pkgtype Not Like '%G128' and Pkgtype Not Like '%PK128' and workweek between " & tBegin & " and " & tEnd & " and Year = " & tYear & " Order by workweek DESC"
Pkgid= "PQFP 128"
case "PK100"
sql="select Avg1, Range1, PkgType from tblFiles where Pkgtype Like '%PK100' and workweek between " & tBegin & " and " & tEnd & " and Year = " & tYear & " Order by workweek DESC"
Pkgid= "PK 100"
case "PK128"
sql="select Avg1, Range1, PkgType from tblFiles where Pkgtype Like '%PK128' and workweek between " & tBegin & " and " & tEnd & " and Year = " & tYear & " Order by workweek DESC"
Pkgid= "PK 128"
End select
RS.Open sql,conn,1,2
sMsg = " No Data Within The WorkWeek you Select Please Select Others WorkWeek."
if rs.recordcount < 1 Then
response.write (sMsg)
else
if rs.recordcount >= 30 then
SET RS=CreateObject("ADODB.Recordset") 'create a recordset
select case request ("pkgtype")
case "P"
sql="select Avg1, Range1, PkgType from tblFiles where Pkgtype Not Like '%G%' and workweek between " & tBegin & " and " & tEnd & " and Year = " & tYear & " Order by workweek DESC"
case "G"
sql="select Avg1, Range1, PkgType from tblFiles where Pkgtype Like '%G%' and workweek between " & tBegin & " and " & tEnd & " and Year = " & tYear & " Order by workweek DESC"
case "208"
sql="select Avg1, Range1, PkgType from tblFiles where Pkgtype Like '%208' and Pkgtype <> '%G208' and workweek between " & tBegin & " and " & tEnd & " and Year = " & tYear & " Order by workweek DESC"
case "128"
sql="select Avg1, Range1, PkgType from tblFiles where Pkgtype Like '%128' and Pkgtype <>'%G128' and Pkgtype <> '%PK128%' and workweek between " & tBegin & " and " & tEnd & " and Year = " & tYear & " Order by workweek DESC"
case "PK100"
sql="select Avg1, Range1, PkgType from tblFiles where Pkgtype Like '%PK100' and workweek between " & tBegin & " and " & tEnd & " and Year = " & tYear & " Order by workweek DESC"
case "PK128"
sql="select Avg1, Range1, PkgType from tblFiles where Pkgtype Like '%PK128' and workweek between " & tBegin & " and " & tEnd & " and Year = " & tYear & " Order by workweek DESC"
End select
else
SET RS=CreateObject("ADODB.Recordset") 'create a recordset
select case request ("pkgtype")
case "P"
sql="select Top 30 Avg1, Range1, PkgType from tblFiles where Pkgtype Not Like '%G%' and workweek <= " & tEnd & " and Year = " & tYear & " Order by workweek DESC"
case "G"
sql="select Top 30 Avg1, Range1, PkgType from tblFiles where Pkgtype Like '%G%' and workweek <= " & tEnd & " and Year = " & tYear & " Order by workweek DESC"
case "208"
sql="select Top 30 Avg1, Range1, PkgType from tblFiles where Pkgtype Like '%208' and Pkgtype <> '%G208' and workweek <= " & tEnd & " and Year = " & tYear & " Order by workweek DESC"
case "128"
sql="select Top 30 Avg1, Range1, PkgType from tblFiles where Pkgtype Like '%128' and Pkgtype <> '%G128' and Pkgtype <> '%PK128%' and workweek <= " & tEnd & " and Year = " & tYear & " Order by workweek DESC"
case "PK100"
sql="select Top 30 Avg1, Range1, PkgType from tblFiles where Pkgtype Like '%PK100' and workweek <= " & tEnd & " and Year = " & tYear & " Order by workweek DESC"
case "PK128"
sql="select Top 30 Avg1, Range1, PkgType from tblFiles where Pkgtype Like '%PK128' and workweek <= " & tEnd & " and Year = " & tYear & " Order by workweek DESC"
End select
end if
Rs.open sql,conn,1,2
prioravg1 = -1
tavg1=0
tdiffavg1=0
trange1=0
count=0%>
<%
Do until rs.eof
avg1 = RS("avg1")
range1= rs("range1")
diffavg1 = 0
If prioravg1 >= 0 Then diffavg1 = ABS( avg1 - prioravg1 ) 'get the mrange of every avg1 and avg1
'===========================================================================================
count = count + 1
trange1= trange1 + range1
Range1ave= trange1/ count ' Get the range Average
Rucl = 1.652 * range1ave ' get the range chart UCL
Rlcl = 0.348 * range1ave' get the range chart LCL
sigma = range1ave / 3.472 ' get the sigma for sample size =15 = 3.472
sixsigma = 6 * sigma
specmean = 800 - 300 ' USl - LSL
cp= specmean / sixsigma ' get the process cp
'===============================================
tavg1 = tavg1 + avg1
tdiffavg1 = tdiffavg1 + diffavg1
atavg1= tavg1 / count ' get the average of avg1
if rs.recordcount > 1 then Rcount = rs.recordcount - 1
if rs.recordcount = 1 then Rcount = 1
atdiffavg1= tdiffavg1 / Rcount ' /////////' get the average of moving range
'=======================================================
UCL = atavg1 + (2.66 * atdiffavg1) ' get the UCL
LCL = atavg1 - (2.66 * atdiffavg1) ' get the LCL
'===================================================
'Below code is to get the CPK
USL = 800 ' upper spec limit
LSL = 300 ' lower spec limit
tsigma= 3 * sigma ' get 3 sigma to calculate the cpk
UCpu = USL - atavg1 ' USL = 800 - atavg1
Cpu = UCpu / tsigma ' get the cpu
UCpl = atavg1 - LSL 'atavg1 - LSL = 300
Cpl = UCpl / tsigma ' get cpl0u
if Cpu > Cpl then Cpk = Cpl ' compare cpu and cpl get the lower value as cpk
if Cpl >= Cpu then Cpk = Cpu
prioravg1=avg1
rs.movenext
Loop%>
<tr>
<Td width="7%" bgcolor="#f1f1f1" align="center"><font face="verdana" size="2"><%=Pkgid%></font></Td><br>
<Td width="7%" bgcolor="#f1f1f1" align="center"><font face="verdana" size="2"><%=FormatNumber(atavg1,2)%></font></Td><br>
<Td width="7%" bgcolor="#f1f1f1" align="center"><font face="verdana" size="2"><%=FormatNumber(atdiffavg1,2)%></font></Td><br>
<Td width="7%" bgcolor="#f1f1f1" align="center"><font face="verdana" size="2"><%=FormatNumber(UCL,2)%></font></Td><br>
<Td width="7%" bgcolor="#f1f1f1" align="center"><font face="verdana" size="2"><%=FormatNumber(LCL,2)%></font></Td><br>
<Td width="7%" bgcolor="#f1f1f1" align="center"><font face="verdana" size="2"><%=count%></font></Td><br>
<Td width="7%" bgcolor="#f1f1f1" align="center"><font face="verdana" size="2"><%=FormatNumber(Range1ave,2)%></font></Td><br>
<Td width="7%" bgcolor="#f1f1f1" align="center"><font face="verdana" size="2"><%=FormatNumber(Rucl,2)%></font></Td><br>
<Td width="7%" bgcolor="#f1f1f1" align="center"><font face="verdana" size="2"><%=FormatNumber(Rlcl,2)%></font></Td><br>
<Td width="7%" bgcolor="#f1f1f1" align="center"><font face="verdana" size="2"><%=Formatnumber(cpk,2)%></font></Td><br>
<Td width="7%" bgcolor="#f1f1f1" align="center"><font face="verdana" size="2"><%=FormatNumber(cp,2)%></font></Td><br>
</tr>
<tr>
<td colspan="12" align="center" bgcolor="#ffffff"><font face="verdana" size="2"><b>
Plating Thickness SPC Control Chart Limit and CPK Data For <%=Ucase(Pkgid)%> From WW <%=tBegin%> To WW <%=tEnd%>.
</font></b></td></tr>
<%end if
end if%>
</table>
As of now I only can get the data in one row which depend on what I select, can I have all data in one table by one click? Pls help tks a lot....
In short I want all my ouput in one table rather then select it one b one...
<%
tBegin = request("beginww")
tEnd = request("endww")
tPkg = request("pkgtype")
tYear = request("wwyear")
%>
<body>
<form name= "frmbrowsepkg" method="POST">
Year: <select name="wwyear" id="wwyear">
<%if tYear = "" then tYear = Year(date)
for t = 2005 to tYear%>
<option value="<%=t%>" <%if t = cint(tYear) then%>selected<%end if%>><%=t%></option>
<%next%>
</select>
Start Week: <select name="beginww" id="beginww">
<% if tBegin = "" then tBegin = 1
for t = 1 to 53%>
<option value="<%=t%>" <%if t = cint(tBegin) then%>selected<%end if%>><%=t%></option>
<%next%>
</select>
End Week: <select name="endww" id="endww">
<% if tEnd = "" then tEnd = 1
for t = 1 to 53%>
<option value="<%=t%>" <%if t = cint(tEnd) then%>selected<%end if%>><%=t%></option>
<%next%>
</select>
Package Type:
<select name="pkgtype" id="pkgtype">
<option Value="P">All Pkg
<option value="G"> All Green Pkg
<option Value = "128">PQFP128
<option Value = "208">PQFP208
<option Value = "PK100">PK100
<option Value = "PK128">PK128
<option value="<%=pkgtype%>"Selected</option>
</select>
<INPUT TYPE="submit" runat="server" VALUE="Cal CPK"></INPUT>
</form>
<%
if Request.ServerVariables("REQUEST_METHOD") = "POST" then
%>
<table width="100%" align="center" bgcolor="#0d5692">
<tr>
<td width="7%" align="center" bgcolor="#ffffff"><font face="verdana" size="2"><b>PKG Type</b></font></td>
<td width="5%" align="center" bgcolor="#ffffff"><font face="verdana" size="2"><b>Mean</b></font></td>
<td width="5%" align="center" bgcolor="#ffffff"><font face="verdana" size="2"><b>Average<br>Moving Range</b></font></td>
<td width="7%" align="center" bgcolor="#ffffff"><font face="verdana" size="2"><b>UCL</b></font></td>
<td width="7%" align="center" bgcolor="#ffffff"><font face="verdana" size="2"><b>LCL</b></font></td>
<td width="7%" align="center" bgcolor="#ffffff"><font face="verdana" size="2"><b>Total<br>Record</b></font></td>
<td width="7%" align="center" bgcolor="#ffffff"><font face="verdana" size="2"><b>Range<br>Mean</b></font></td>
<td width="7%" align="center" bgcolor="#ffffff"><font face="verdana" size="2"><b>Range<br>UCL</b></font></td>
<td width="7%" align="center" bgcolor="#ffffff"><font face="verdana" size="2"><b>Range<br>LCL</b></font></td>
<td width="5%" align="center" bgcolor="#ffffff"><font face="verdana" size="2"><b>CPK</b></font></td>
<td width="5%" align="center" bgcolor="#ffffff"><font face="verdana" size="2"><b>CP</b></font></td>
</tr>
<%
SET RS=CreateObject("ADODB.Recordset") 'create a recordset
select case request ("pkgtype")
case "P"
sql="select Avg1, Range1, PkgType from tblFiles where Pkgtype Not Like '%G%' and workweek between " & tBegin & " and " & tEnd & " and Year = " & tYear & " Order by workweek DESC"
Pkgid= "All Sn/Pb Pkg"
case "G"
sql="select Avg1, Range1, PkgType from tblFiles where Pkgtype Like '%G%' and workweek between " & tBegin & " and " & tEnd & " and Year = " & tYear & " Order by workweek DESC"
Pkgid= "All Green Pkg"
case "208"
sql="select Avg1, Range1, PkgType from tblFiles where Pkgtype Like '%208' and Pkgtype Not Like '%G208' and workweek between " & tBegin & " and " & tEnd & " and Year = " & tYear & " Order by workweek DESC"
Pkgid= "PQFP 208"
case "128"
sql="select Avg1, Range1, PkgType from tblFiles where Pkgtype Like '%128' and Pkgtype Not Like '%G128' and Pkgtype Not Like '%PK128' and workweek between " & tBegin & " and " & tEnd & " and Year = " & tYear & " Order by workweek DESC"
Pkgid= "PQFP 128"
case "PK100"
sql="select Avg1, Range1, PkgType from tblFiles where Pkgtype Like '%PK100' and workweek between " & tBegin & " and " & tEnd & " and Year = " & tYear & " Order by workweek DESC"
Pkgid= "PK 100"
case "PK128"
sql="select Avg1, Range1, PkgType from tblFiles where Pkgtype Like '%PK128' and workweek between " & tBegin & " and " & tEnd & " and Year = " & tYear & " Order by workweek DESC"
Pkgid= "PK 128"
End select
RS.Open sql,conn,1,2
sMsg = " No Data Within The WorkWeek you Select Please Select Others WorkWeek."
if rs.recordcount < 1 Then
response.write (sMsg)
else
if rs.recordcount >= 30 then
SET RS=CreateObject("ADODB.Recordset") 'create a recordset
select case request ("pkgtype")
case "P"
sql="select Avg1, Range1, PkgType from tblFiles where Pkgtype Not Like '%G%' and workweek between " & tBegin & " and " & tEnd & " and Year = " & tYear & " Order by workweek DESC"
case "G"
sql="select Avg1, Range1, PkgType from tblFiles where Pkgtype Like '%G%' and workweek between " & tBegin & " and " & tEnd & " and Year = " & tYear & " Order by workweek DESC"
case "208"
sql="select Avg1, Range1, PkgType from tblFiles where Pkgtype Like '%208' and Pkgtype <> '%G208' and workweek between " & tBegin & " and " & tEnd & " and Year = " & tYear & " Order by workweek DESC"
case "128"
sql="select Avg1, Range1, PkgType from tblFiles where Pkgtype Like '%128' and Pkgtype <>'%G128' and Pkgtype <> '%PK128%' and workweek between " & tBegin & " and " & tEnd & " and Year = " & tYear & " Order by workweek DESC"
case "PK100"
sql="select Avg1, Range1, PkgType from tblFiles where Pkgtype Like '%PK100' and workweek between " & tBegin & " and " & tEnd & " and Year = " & tYear & " Order by workweek DESC"
case "PK128"
sql="select Avg1, Range1, PkgType from tblFiles where Pkgtype Like '%PK128' and workweek between " & tBegin & " and " & tEnd & " and Year = " & tYear & " Order by workweek DESC"
End select
else
SET RS=CreateObject("ADODB.Recordset") 'create a recordset
select case request ("pkgtype")
case "P"
sql="select Top 30 Avg1, Range1, PkgType from tblFiles where Pkgtype Not Like '%G%' and workweek <= " & tEnd & " and Year = " & tYear & " Order by workweek DESC"
case "G"
sql="select Top 30 Avg1, Range1, PkgType from tblFiles where Pkgtype Like '%G%' and workweek <= " & tEnd & " and Year = " & tYear & " Order by workweek DESC"
case "208"
sql="select Top 30 Avg1, Range1, PkgType from tblFiles where Pkgtype Like '%208' and Pkgtype <> '%G208' and workweek <= " & tEnd & " and Year = " & tYear & " Order by workweek DESC"
case "128"
sql="select Top 30 Avg1, Range1, PkgType from tblFiles where Pkgtype Like '%128' and Pkgtype <> '%G128' and Pkgtype <> '%PK128%' and workweek <= " & tEnd & " and Year = " & tYear & " Order by workweek DESC"
case "PK100"
sql="select Top 30 Avg1, Range1, PkgType from tblFiles where Pkgtype Like '%PK100' and workweek <= " & tEnd & " and Year = " & tYear & " Order by workweek DESC"
case "PK128"
sql="select Top 30 Avg1, Range1, PkgType from tblFiles where Pkgtype Like '%PK128' and workweek <= " & tEnd & " and Year = " & tYear & " Order by workweek DESC"
End select
end if
Rs.open sql,conn,1,2
prioravg1 = -1
tavg1=0
tdiffavg1=0
trange1=0
count=0%>
<%
Do until rs.eof
avg1 = RS("avg1")
range1= rs("range1")
diffavg1 = 0
If prioravg1 >= 0 Then diffavg1 = ABS( avg1 - prioravg1 ) 'get the mrange of every avg1 and avg1
'===========================================================================================
count = count + 1
trange1= trange1 + range1
Range1ave= trange1/ count ' Get the range Average
Rucl = 1.652 * range1ave ' get the range chart UCL
Rlcl = 0.348 * range1ave' get the range chart LCL
sigma = range1ave / 3.472 ' get the sigma for sample size =15 = 3.472
sixsigma = 6 * sigma
specmean = 800 - 300 ' USl - LSL
cp= specmean / sixsigma ' get the process cp
'===============================================
tavg1 = tavg1 + avg1
tdiffavg1 = tdiffavg1 + diffavg1
atavg1= tavg1 / count ' get the average of avg1
if rs.recordcount > 1 then Rcount = rs.recordcount - 1
if rs.recordcount = 1 then Rcount = 1
atdiffavg1= tdiffavg1 / Rcount ' /////////' get the average of moving range
'=======================================================
UCL = atavg1 + (2.66 * atdiffavg1) ' get the UCL
LCL = atavg1 - (2.66 * atdiffavg1) ' get the LCL
'===================================================
'Below code is to get the CPK
USL = 800 ' upper spec limit
LSL = 300 ' lower spec limit
tsigma= 3 * sigma ' get 3 sigma to calculate the cpk
UCpu = USL - atavg1 ' USL = 800 - atavg1
Cpu = UCpu / tsigma ' get the cpu
UCpl = atavg1 - LSL 'atavg1 - LSL = 300
Cpl = UCpl / tsigma ' get cpl0u
if Cpu > Cpl then Cpk = Cpl ' compare cpu and cpl get the lower value as cpk
if Cpl >= Cpu then Cpk = Cpu
prioravg1=avg1
rs.movenext
Loop%>
<tr>
<Td width="7%" bgcolor="#f1f1f1" align="center"><font face="verdana" size="2"><%=Pkgid%></font></Td><br>
<Td width="7%" bgcolor="#f1f1f1" align="center"><font face="verdana" size="2"><%=FormatNumber(atavg1,2)%></font></Td><br>
<Td width="7%" bgcolor="#f1f1f1" align="center"><font face="verdana" size="2"><%=FormatNumber(atdiffavg1,2)%></font></Td><br>
<Td width="7%" bgcolor="#f1f1f1" align="center"><font face="verdana" size="2"><%=FormatNumber(UCL,2)%></font></Td><br>
<Td width="7%" bgcolor="#f1f1f1" align="center"><font face="verdana" size="2"><%=FormatNumber(LCL,2)%></font></Td><br>
<Td width="7%" bgcolor="#f1f1f1" align="center"><font face="verdana" size="2"><%=count%></font></Td><br>
<Td width="7%" bgcolor="#f1f1f1" align="center"><font face="verdana" size="2"><%=FormatNumber(Range1ave,2)%></font></Td><br>
<Td width="7%" bgcolor="#f1f1f1" align="center"><font face="verdana" size="2"><%=FormatNumber(Rucl,2)%></font></Td><br>
<Td width="7%" bgcolor="#f1f1f1" align="center"><font face="verdana" size="2"><%=FormatNumber(Rlcl,2)%></font></Td><br>
<Td width="7%" bgcolor="#f1f1f1" align="center"><font face="verdana" size="2"><%=Formatnumber(cpk,2)%></font></Td><br>
<Td width="7%" bgcolor="#f1f1f1" align="center"><font face="verdana" size="2"><%=FormatNumber(cp,2)%></font></Td><br>
</tr>
<tr>
<td colspan="12" align="center" bgcolor="#ffffff"><font face="verdana" size="2"><b>
Plating Thickness SPC Control Chart Limit and CPK Data For <%=Ucase(Pkgid)%> From WW <%=tBegin%> To WW <%=tEnd%>.
</font></b></td></tr>
<%end if
end if%>
</table>
As of now I only can get the data in one row which depend on what I select, can I have all data in one table by one click? Pls help tks a lot....
In short I want all my ouput in one table rather then select it one b one...