2013-03-18 2 views
0

나는 고전적인 ASP 사람이라고 주장하지 않지만 가끔은 자신이해야 할 일을해야합니다. 내 문제는 이것이 ASP를 통해 사용자 정의 빌드 된 보고서이며 사용자가 SubTotals 및 Grand Total을 실행하기를 원한다는 것과 솔직히 나는 그것에 대해 어떻게 해야할지 잘 모르겠다는 것입니다. 현재 전체 보고서는 이와 같이 줄 바꿈되어 표시되는 방식이 문제에별로 중요하지 않습니다. ASP Do While 루프 합계 및 부분합

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

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

는 CurRep에 대한 값을 추가하고 난 내가 어떤 수단에 의해 ASP 전문가 아니라고 언급 한 바와 같이 내가 얻을 수있는 모든 도움을 크게 감상 할 수

<% 

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

'합계의'로 표시됩니다. NickG

감사합니다. 루프의 바깥 쪽 루프는 데이터를 모두 표시하고 총계를 표시합니다. (실제로는 아님) 지금은 내가 실행하는 것이 .MoveNext가 이전에 눌려진 것입니다. 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%> 

의 하위 합계를 표시하는 의미 newrep 당신이 내가 그들을 표시 한 후 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으로 재설정하기도하지만 다음 값은 어디로 가야할지 모르지만 지금까지 도움을 주셔서 감사합니다! –

+0

내 편집 된 답변보기 – stare

+0

중첩 루프없이 할 수 있다고 생각하지 않습니다. 데이터를 표시하는 루프 외부에 있기 때문에 grandtotals가 제대로 작동하지만 소계가 나를 죽이고 있습니다. 추가 정보로 내 게시물을 업데이트했습니다. 만약 당신이 좀 걸릴 수 있다면, 바쁘신데, 내가 말할 수있는 것보다 더 많은 도움을 주신다는 것을 이해합니다. –