ASP Do While循环总计和小计

时间:2013-03-18 13:13:51

标签: loops asp-classic do-while totals

我并不认为自己是一个经典的ASP人,但有时你必须做你必须做的事情。我的问题是,这是一个通过ASP自定义构建的报告,用户想要运行SubTotals和Grand Total也显示,老实说,我只是不确定如何去做。目前整个报告都是这样包装的,它的显示方式与问题无关。

<%do while (adoRsTrade.AbsolutePage = iPageCurrent) and (not adoRsTrade.EOF)
NewRep = adoRsTrade("calIncludedRep")

if CurRep <> NewRep or FirstTime="T" and (not adorsTrade.BOF) then %>

将该CurRep的值相加并将其显示为“小计”

<%

FirstTime="F"
CurRep = adoRsTrade("calIncludedRep")
adoRsTrade.MoveNext
loop %>

我能得到的任何帮助都会非常感激,因为我提到我无论如何都不是ASP大师。 谢谢, NickG

更新小计的内容;由于我可以在循环外重新运行do while循环显示所有数据并将其总计,因此我可以轻松查看(不是真的)现在我遇到的是.MoveNext是先前命中的。让我能够检查NewRep;这里是小计的总和,以及检查它是否为newrep,这意味着显示前代表的小计

<%do while (adoRsTrade.AbsolutePage = iPageCurrent) and (not adoRsTrade.EOF)
NewRep = adoRsTrade("calIncludedRep")

if CurRep = NewRep then
        curPrincipal = adoRsTrade("mPrincipal")
        totPrincipal = totPrincipal + curPrincipal
            curInterest = adoRsTrade("mInterest")
            totInterest = totInterest + curInterest
        curCommission = adoRsTrade("calCommission")
        totCommission = totCommission + curCommission
            curSECFee = adoRsTrade("mSECFee")
            totSECFee = totSECFee + curSECFee
        curSvcFee = adoRsTrade("mSvcCharge")
        totSvcFee = totSvcFee + curSvcFee
            curNet = adoRsTrade("mNetAmount")
            totNet = totNet + curNet
end if    
if CurRep <> NewRep or FirstTime="T" and (not adorsTrade.BOF) then
  If FirstTime <> "T" then%>
      <TR>
        <td>
            <table class='FontStandardMinus1' border=0 cellPadding=0 align='left' cellSpacing=0 width="100%" bgcolor='#ffffff'>
                 <TR>
                    <td width="59%" align="left"><b>SubTotals<!-- for <%Response.Write(CurRep) %>-->:</b></td>
                    <td width="10%" valign=top align=right><%=FormatNumber(totPrincipal,2)%></td>
                    <td width="7%" valign=top align=right><%=FormatNumber(totInterest,2)%></td>
                    <td width="7%" valign=top align=right><%=FormatNumber(totCommission,2)%></td>
                    <td width="5%" valign=top align=right><%=FormatNumber(totSECFee,2)%></td>
                    <td width="4%" valign=top align=right><%=FormatNumber(totSvcFee,2)%></td>
                    <td width="9%" valign=top align=right><%=FormatNumber(totNet,2)%></td>
                </TR>
            </table>
        </td>
    </TR>
<%end if      
curPrincipal = 0
totPrincipal = 0
curInterest = 0
totInterest = 0
curCommission = 0
totCommission = 0
curSECFee = 0
totSECFee = 0
curSvcFee = 0
totSvcFee = 0
curNet = 0
totNet = 0 %>
<TR>
<TD width="100%">
<table class='FontStandardMinus1' border=0 cellPadding=0 align='left' cellSpacing=0 width="100%" bgcolor='#ffffff'>
<tr>
<td width=100%><b><%=adoRsTrade("calIncludedRep")%></b></td>

</tr>
</table>
</TD>
</TR>
<%end if%>
<%

FirstTime="F"
'CalCom = CalCom + adoRsTrade("calCommission")
CurRep = adoRsTrade("calIncludedRep")
adoRsTrade.MoveNext

loop%>

所以你可以看到我在一个表中显示它后尝试将值重置为0,但该表只在点击中点击.MoveNext后显示,这意味着即使我想显示记录1-5加起来,记录6已经被.MoveNext击中并被从值集中丢弃。很抱歉这个很长,但我讨厌评论不能包含更新的代码。 谢谢你的帮助

1 个答案:

答案 0 :(得分:1)

假设你在循环之后输出变量totPrincipal,totInterest,totCommission,我能想到的唯一问题是数据类型和rs.MoveFirst。

BTW:出于性能原因,尝试在单个循环中执行此操作!

Dim subtotPrincipal: subtotPrincipal = 0
Dim totPrincipal: totPrincipal = 0
Dim CurRep: CurRep = 0
Dim NewRep: NewRep = 0

adoRsTrade.MoveFirst
Do 
    NewRep = adoRsTrade("calIncludedRep")       
    ...
    subtotPrincipal = subtotPrincipal + CLng(adoRsTrade("mPrincipal"))
    totPrincipal = totPrincipal + CLng(adoRsTrade("mPrincipal"))
    ...

    If (CurRep <> NewRep And Not adorsTrade.BOF) Or adoRsTrade.EOF Then
        Response.Write subtotPrincipal
        subtotPrincipal = 0
    End If

    CurRep = NewRep
    adorsTrade.MoveNext
Loop Until adoRsTrade.EOF

Response.Write totPrincipal