Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Count error

  1. #1
    Regular Coder
    Join Date
    May 2003
    Location
    Stockholm, Sweden
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Count error

    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

    Code:
    <!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>

  • #2
    Senior Coder BarrMan's Avatar
    Join Date
    Feb 2005
    Location
    Israel.
    Posts
    1,644
    Thanks
    69
    Thanked 83 Times in 82 Posts
    Code:
    while not objrs.BOF and not objrs.EOF
    I think this causes the problem.

    This is what you should do:
    Code:
    while not objrs.EOF

  • #3
    Regular Coder
    Join Date
    May 2003
    Location
    Stockholm, Sweden
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I tried that and nothing happend

    see anything else that could cause this?

    /Speedy


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •