Loops ASP Do While循环总计和小计

Loops ASP Do While循环总计和小计,loops,asp-classic,do-while,totals,Loops,Asp Classic,Do While,Totals,我并不自称是一个典型的ASP人,但有时你必须做你必须做的事。我的问题是,这是一个通过ASP定制的报告,用户希望运行小计和显示总计,老实说,我只是不知道如何进行。目前整个报告都是这样包装的,它的显示方式对问题没有太大影响 <%do while (adoRsTrade.AbsolutePage = iPageCurrent) and (not adoRsTrade.EOF) NewRep = adoRsTrade("calIncludedRep") if CurRep <> Ne

我并不自称是一个典型的ASP人,但有时你必须做你必须做的事。我的问题是,这是一个通过ASP定制的报告,用户希望运行小计和显示总计,老实说,我只是不知道如何进行。目前整个报告都是这样包装的,它的显示方式对问题没有太大影响

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

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

将该电流的值相加并显示为“小计”

<%

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

如果我能得到任何帮助,我将不胜感激,因为我提到我无论如何都不是ASP大师。 非常感谢。 尼克

更新小计资料;总计完成了,因为我可以在循环外重新运行do while循环。该循环显示所有数据并对其进行总计,轻松烦躁(不是真的)。现在我遇到的是,在我能够检查NewRep之前,点击了.MoveNext;下面是小计的总计以及检查是否为新代表,这意味着显示前代表的小计

<%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%>

小计:

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

顺便说一句:出于性能原因,请尝试在单个循环中执行此操作

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
Dim subtotPrincipal:subtotPrincipal=0
Dim totPrincipal:totPrincipal=0
变暗电流:电流=0
Dim NewRep:NewRep=0
首先崇拜
做
NewRep=adoRsTrade(“calIncludedRep”)
...
次原则=次原则+CLng(adoRsTrade(“主原则”))
totPrincipal=totPrincipal+CLng(adoRsTrade(“MPPrincipal”))
...
如果(CurRep NewRep而非adorsTrade.BOF)或adorsTrade.EOF,则
回复。写小标题
次原则=0
如果结束
CurRep=NewRep
下一步
循环直到adoRsTrade.EOF
回复。写一封信给校长

感谢您的回复,在检查确保我在最后一页后,我使用上面循环外的MoveFirst,能够正确计算总计。这是一大步。然而,小计给我带来了问题,因为它们不断地添加我显示后下一组的第一个值。我甚至在显示后将所有变量重置为=0,但下一个值被添加到这些变量中,不确定要去哪里,但感谢您迄今为止的帮助!如果没有嵌套循环,我不认为我能做到这一点,因为grandtotals可以很好地工作,因为它们在循环之外显示数据,但是小计让我很痛苦,我更新了我的帖子,提供了更多信息,如果你能看一看,我理解你很忙,我非常感谢你的帮助,而不是我能告诉yaOk一些评论:1。您必须在SQL中按calIncludedRep对数据进行排序,否则此解决方案将永远无法工作2。您可以简化加法,例如:
totPrincipal=totPrincipal+adoRsTrade(“mPrincipal”)
并删除重置为零3的操作。您正在将第一次迭代后的标志
FirstTime
设置为F no mather what-我看不出这有什么意义?4.检查嵌套的IFs-我不认为这些是必要的-你为什么不一步写出小计和分隔?我实际上明白了,我在已经添加了新记录集的第一个值之后重置了这些值,这导致我的数据有点偏离。现在我唯一要弄清楚的是如何得到数据集中最后一条记录的小计,我不确定。使用If AdorsTrade.Index=(AdorsTrade.RecordCount-1)并不能做到这一点,但感谢您所做的一切,您肯定是我到达这里的唯一原因,我很高兴您能找到它您可以将
RecordCount
存储在变量
rsCount=AdorsTrade.RecordCount
(不要忘记使用
adodb.CursorLocation=3
)中,然后在循环结束时将其与一个简单的递增变量
count=count+1
进行比较。