Hej igen <code> Tackar Andreas, som vanligt. Men jag får upp följande på den kodsnutten Fast av resultatet att döma skulle den nog behövas. Den första loopen flippar ut lite i summeringen. I stället för att loopa ut resultatet, loopar den ut innehållet i kolumnerna i en <td></td>. Ska försöka klura ut det.Summera kolumn i array
Jag har tittat lite på denna kodsnutt i kurser o artiklar och undrar över hur man ska summera kolumnen. Exempel: jag hämtar ut 10 rader ur 3 kolumner och därefter vill jag summera i den elfte raden, sedan hämta ut nästa 10 o summera i den 22:a osv osv
<%
arrayData = rs.GetRows()
rs.Close
Set rs = Nothing
conn.Close
Set conn = Nothing
Response.Write("<table>")
For iRad = 0 To Ubound(arrayData, 2)
Response.Write("<tr>")
For iKol = 0 To Ubound(arrayData, 1)
Response.Write("<td>" & arrayData(iKol, iRad) & "</td>")
Next
Response.Write("</tr>")
Next
Response.Write("</table>")
%>
MVH/Uffe
Sv: Summera kolumn i array
<%
Dim Sum()
Dim iSections
Const SectionSize = 10
arrayData = rs.GetRows()
rs.Close
Set rs = Nothing
conn.Close
Set conn = Nothing
ReDim Sum(Ubound(arrayData, 1))
For iSections = 0 to Ubound(arrayData, 2) - SectionSize Step SectionSize
Response.Write("<table>")
For iRad = iSections To iSections + SectionSize - 1
Response.Write("<tr>")
For iKol = 0 To Ubound(arrayData, 1)
Response.Write("<td>" & arrayData(iKol, iRad) & "</td>")
Sum(iKol) = Sum(iKol) + arrayData(iKol, iRad) & "</td>")
Next
Response.Write("</tr>")
Next
Response.Write("<tr>")
For iKol = 0 To Ubound(arrayData, 1)
Response.Write("<td>" & Sum(iKol) & "</td>")
Sum(iKol) = 0
Next
Response.Write("</tr>")
Response.Write("</table>")
Next
If Ubound(arrayData, 2) > iSections Then
Response.Write("<table>")
For iRad = iSections To Ubound(arrayData, 2)
Response.Write("<tr>")
For iKol = 0 To Ubound(arrayData, 1)
Response.Write("<td>" & arrayData(iKol, iRad) & "</td>")
Sum(iKol) = Sum(iKol) + arrayData(iKol, iRad) & "</td>")
Next
Response.Write("</tr>")
Next
Response.Write("<tr>")
For iKol = 0 To Ubound(arrayData, 1)
Response.Write("<td>" & Sum(iKol) & "</td>")
Sum(iKol) = 0
Next
Response.Write("</tr>")
Response.Write("</table>")
End If
%>
</code>Sv: Summera kolumn i array
Feltyp:
Kompileringsfel i Microsoft VBScript (0x800A0401)
Slut på programsats förväntas.
/evgk/course_mall.asp, line 108, column 55
Sum(iKol) = Sum(iKol) + arrayData(iKol, iRad) & "</td>")
------------------------------------------------------^
<%
Dim Sum()
Dim iSections
Const SectionSize = 9
arrayData = rs.GetRows()
rs.Close
Set rs = Nothing
conn.Close
Set conn = Nothing
ReDim Sum(Ubound(arrayData, 1))
For iSections = 0 to Ubound(arrayData, 2) - SectionSize Step SectionSize
Response.Write("<table>")
For iRad = iSections To iSections + SectionSize - 1
Response.Write("<tr>")
For iKol = 0 To Ubound(arrayData, 1)
Response.Write("<td>" & arrayData(iKol, iRad) & "</td>")
Sum(iKol) = Sum(iKol) + arrayData(iKol, iRad) & "</td>") 'Här är den raden
Next
Response.Write("</tr>")
Next
Response.Write("<tr>")
For iKol = 0 To Ubound(arrayData, 1)
Response.Write("<td>" & Sum(iKol) & "</td>")
Sum(iKol) = 0
Next
Response.Write("</tr>")
Response.Write("</table>")
Next
If Ubound(arrayData, 2) > iSections Then
Response.Write("<table>")
For iRad = iSections To Ubound(arrayData, 2)
Response.Write("<tr>")
For iKol = 0 To Ubound(arrayData, 1)
Response.Write("<td>" & arrayData(iKol, iRad) & "</td>")
Sum(iKol) = Sum(iKol) + arrayData(iKol, iRad) & "</td>") 'Finns en liknande rad i här
Next
Response.Write("</tr>")
Next
Response.Write("<tr>")
For iKol = 0 To Ubound(arrayData, 1)
Response.Write("<td>" & Sum(iKol) & "</td>")
Sum(iKol) = 0
Next
Response.Write("</tr>")
Response.Write("</table>")
End If
%>Sv: Summera kolumn i array