...

View Full Version : Count error



Speedy
03-04-2006, 10:15 PM
Hi,

I have a script that gets the average score from a number of golfrounds
for example:

Average for the total score:
in 12 played rounds the total score is 299 shots so the script should
count 299 / 12 = 24,92 but as it is now it says 22,91


I also want to get the average score per hole

for example:
1,1,1,1,2,1,1,1,1,2,1,1 = 14
14 / 12 = 1,17 but as it is now it says 1,08
(14 / 13 = 1,08)

so it looks like it divides by one to much, anyone that can see what's wrong?

Here you can see how it looks now: http://www.monow,se/borg/sub/test4.asp

/Speedy



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title></title>
<script language="JavaScript" type="text/javascript" src="/templates/menu.js"></script>
<link href="stylesheets/stylesheet1.css" rel="stylesheet" type="text/css" >
<link href="stylesheets/links.css" rel="stylesheet" type="text/css" >
<link rel="stylesheet" type="text/css" href="stylesheets/table.css">

</head>

<body>

<table width="695" height="0" border="0" cellspacing="5">
<tr>
<td>
<%
Sub createNewTableStart(endPrevTable)
if endPrevTable then response.write vbCrLf & "</table>" & vbCrLf & "<br />" & vbCrLf
%>

<span style="padding-left: 28px;" class="rubrik"><b><%=objrs("CompName") %>&nbsp; (<%= objrs("Date") %>)</b></span>

<br>

<table align="center" border="1" style="border-collapse: collapse" bordercolor="1px solid #000000">
<tr bgcolor="#CDD5E4" style="font-weight: bold">
<% For I = 1 to 18 %>
<td width="30" align="center"><a href="top10.asp?Show=Top10&Lane=<%=I%>" target=""><%=I%></a></td>
<% Next %>
<td width="30" align="center">Tot</td>
</tr>

<% End Sub %>

<%
dim Conn, objrs, i, y, prevDate, currDate, strTot
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("db/eb.mdb")
Set objrs = Conn.Execute("SELECT tbl_player.Namn, tbl_player.Efternamn, tbl_res.CompYear, tbl_res.Course, tbl_res.AMT1, tbl_res.AMT2, tbl_res.AMT3, tbl_res.AMT4, tbl_res.AMT5, tbl_res.AMT6, tbl_res.AMT7, tbl_res.AMT8, tbl_res.AMT9, tbl_res.AMT10, tbl_res.AMT11, tbl_res.AMT12, tbl_res.AMT13, tbl_res.AMT14, tbl_res.AMT15, tbl_res.AMT16, tbl_res.AMT17, tbl_res.AMT18, tbl_res.TOTAL, tbl_res.Date, tbl_res.CompName FROM tbl_player INNER JOIN tbl_res ON tbl_player.PlayerId=tbl_res.PlayerId WHERE tbl_res.Surface ='EB' ORDER BY tbl_res.Date, tbl_res.Varv")


Dim arrSum, Counter
Counter = 0
Redim arrSum(17)
while not objrs.BOF and not objrs.EOF
Counter = Counter +1
currDate = objrs("Date")
if IsEmpty(prevDate) then 'first iteration
createNewTableStart(false)
elseif prevDate <> currDate then

Response.Write("<tr bgcolor=""#CDD5E4"" style=""font-weight: bold"">" & vbCrlf)

For i = 0 To 17 %>
<td align="center"><% MySumma = (arrSum(i)/Counter) : Response.Write FormatNumber(MySumma,2)%></td>
<% Next%>
<td align="center">

<% set antalV = Conn.Execute("SELECT tbl_res.CompName, Count(tbl_res.TOTAL) AS Ant FROM tbl_res GROUP BY tbl_res.CompName HAVING tbl_res.CompName='"&objrs("CompName")&"'")%>
<% Set snitt = Conn.Execute("SELECT tbl_res.CompName, Sum(tbl_res.TOTAL) AS Summa FROM tbl_res GROUP BY tbl_res.CompName HAVING tbl_res.CompName='"&objrs("CompName")&"'")%>

<% inSvar1 = snitt("Summa")
inSvar2 = AntalV("Ant")
inSvar = Insvar1 / Insvar2
Response.Write formatnumber(Insvar,2) %>

</td>



<%
Counter = 0


createNewTableStart(true)

Redim arrSum(17)

end if

y = y + 1
If y Mod 2 = 0 Then
%>

<tr bgcolor="#EEEEEE">
<% Else %>
<tr bgcolor="#FFFFFF">
<% End If %>

<%
For I = 1 to 18
If len(objrs("AMT" & I)) > 0 Then
arrSum(I-1) = arrSum(I-1) + cint(objrs("AMT" & I))

End If
%>

<td align="center"><%=objrs("AMT" & I)%></td>
<% Next %>
<td align="center">

<%
strTot = objrs("TOTAL")
if strTot < 20 then
response.write "<span class=""blueText"">"&strTot&"</span>"
elseif strTot < 25 then
response.write "<span class=""greenText"">"&strTot&"</span>"
elseif strTot < 30 then
response.write "<span class=""redText"">"&strTot&"</span>"
elseif strTot > 29 then
response.write "<span class=""blackText"">"&strTot&"</span>"
End if
response.write vbCrLf & "</td>" & vbCrLf & "</tr>" & vbCrLf
prevDate = currDate
objrs.movenext
wend

if i=0 then 'empty recordset
response.write "<tr><td colspan=""19"">Det finns inga resultat!</td></tr>"
end if
%>

</table>
<%
'close and kill recordset/connection objects
objrs.close
set objrs = nothing
Conn.close
set Conn = nothing
%>
</td>
</tr>
</table>

</td>
</tr>
</table>
</body>
</html>

BarrMan
03-05-2006, 12:49 PM
while not objrs.BOF and not objrs.EOF
I think this causes the problem.

This is what you should do:

while not objrs.EOF

Speedy
03-05-2006, 07:59 PM
I tried that and nothing happend :(

see anything else that could cause this?

/Speedy



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum