2013-03-18 94 views
0

我不認爲是一個經典的ASP人,但有時你必須做你應該做的。我的問題是,這是一個通過ASP定製的報告,用戶想要運行SubTotals和總計顯示,老實說,我只是不知道該怎麼去做。目前整個報告都是這樣封裝的,它的顯示方式對於這個問題並不重要。ASP雖然循環總計和小計

<%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循環以外的循環顯示所有數據並總計它,現在我碰到的是easy-peezy(不是真正的)是.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

假設您在循環後輸出變量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 
+0

感謝您的答覆,我是能夠得到上述檢查,以確保我是在最後一頁後,使用的MoveFirst環路以外正常工作的總計。所以這是一大步。然而,小計給我帶來了問題,因爲他們在我展示之後不斷添加應該是下一組的第一個值。我甚至在顯示後將所有變量重置爲= 0,但將下一個值添加到這些變量中,不確定要去哪裏,但感謝您的幫助! – 2013-03-18 16:09:50

+0

看到我編輯的答案 – stare 2013-03-18 16:22:21

+0

我不認爲如果沒有嵌套循環就可以做到這一點,grandtotals可以正常工作,因爲它們在循環之外以顯示數據,但小計正在殺死我,我更新了我的帖子並提供了更多信息如果你可以看看,我明白你很忙,並欣賞幫助超過我可以告訴你 – 2013-03-18 16:56:36