Foros del Web » Programando para Internet » ASP Clásico »

como sumar y promediar celdas?

Estas en el tema de como sumar y promediar celdas? en el foro de ASP Clásico en Foros del Web. Hola, estoy en un lío. En la tabla donde levanto de la db de acces, necesito realizar dos funciones: 1: que un code me saque ...
  #1 (permalink)  
Antiguo 20/02/2006, 12:00
Avatar de JJF
JJF
 
Fecha de Ingreso: mayo-2005
Mensajes: 205
Antigüedad: 20 años
Puntos: 0
Sonrisa como sumar y promediar celdas?

Hola, estoy en un lío. En la tabla donde levanto de la db de acces, necesito realizar dos funciones:
1: que un code me saque un promedio de las celdas "asis"
2: que un code me sume las celdas "of."

alguien me puede decir el cómo?
Por las dudas aclaro que para el while incluyo un archivo externo.


<%@ Language=VBScript %>

<%
Dim Conn
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ= " & Server.MapPath("db/CELULASVDF.mdb")
%>
<% ssql = "Select * from CELULAJOVEN"

Set RS=Conn.Execute(ssql) %>
<html>

<head>

<title></title>
</head>
<!--#include file="SCRIPX10/scripx10-cab.txt"-->
<body link="#00FF00" vlink="#FFFF00">

<p align="center">&nbsp;<b><font face="Verdana" size="3"><u>INFORME RED
DE JÓVENES</u></font></b>&nbsp;</p>
<table border="0" width="100%" cellspacing="1" bordercolorlight="#336699" bordercolordark="#336699" bordercolor="#14274E">
<tr>
<td width="27%" align="center"><b><font size="1" face="Arial">LIDER</font></b></td>
<td width="8%" align="center"><b><font size="1" face="Arial">GENERACIÓN</font></b></td>
<td width="8%" align="center"><b><font size="1" face="Arial">DÍA
</font></b></td>
<td width="6%" align="center"><b><font size="1" face="Arial">Nº&nbsp;
CÉLULA</font></b></td>
<td width="9%" align="center" colspan="2"><b><font size="1" face="Arial">SEMANA
1</font></b></td>
<td width="8%" align="center" colspan="2"><b><font size="1" face="Arial">SEMANA
2</font></b></td>
<td width="8%" align="center" colspan="2"><b><font face="Arial"><font size="1">SEMANA
</font><font size="1">3</font></font></b></td>
<td width="8%" align="center" colspan="2"><b><font face="Arial"><font size="1">SEMANA
</font><font size="1">4</font></font></b></td>
<td width="3%" align="center" colspan="2"><b><font face="Arial"><font size="1">SEMANA
</font><font size="1">5</font></font></b></td>
<td width="11%" align="center"><b><font size="1" face="Arial">PROMEDIO</font></b></td>
<td width="11%" align="center"><b><font size="1" face="Arial">TOTAL</font></b></td>
</tr>
<tr>
<td width="27%" align="center">&nbsp;</td>
<td width="8%" align="center">&nbsp;</td>
<td width="8%" align="center">&nbsp;</td>
<td width="8%" align="center">&nbsp;</td>
<td width="3%" align="center"><b><font size="1" face="Arial">ASIS</font></b></td>
<td width="4%" align="center"><b><font size="1" face="Arial">OF</font></b></td>
<td width="4%" align="center"><b><font size="1" face="Arial">ASIS.</font></b></td>
<td width="4%" align="center"><b><font size="1" face="Arial">OF.</font></b></td>
<td width="4%" align="center"><b><font size="1" face="Arial">ASIS.</font></b></td>
<td width="4%" align="center"><b><font size="1" face="Arial">OF.</font></b></td>
<td width="4%" align="center"><b><font size="1" face="Arial">ASIS.</font></b></td>
<td width="4%" align="center"><b><font size="1" face="Arial">OF.</font></b></td>
<td width="3%" align="center"><b><font size="1" face="Arial">ASIS.</font></b></td>
<td width="4%" align="center"><b><font size="1" face="Arial">OF.</font></b></td>
<td width="9%" align="center"><font face="Arial" size="1"><b>ASISTENCIA</b></font></td>
<td width="9%" align="center"><font face="Arial" size="1"><b>OFRENDA</b></font></td>
</tr>

<% While ((Repeat1__numRows <> 0) AND (NOT RS.EOF))%>
<tr>

<td width="27%" align="left"><font size="2" face="Arial"><b><%=RS("ENCARGADO")%></b></font></td>
<td width="8%" align="center"><font size="1" face="Arial"><%=RS("NUMCELULA")%></font></td>
<td width="8%" align="center"><font size="1" face="Arial"><%=RS("DIACELULA")%></font></td>
<td width="8%" align="center"><font size="1" face="Arial"><%=RS("NUMCELULA")%></font></td>

<td width="3%" align="center"><font size="1" face="Arial"><%=RS("DIA1")%></font></td>
<td width="4%" align="center"><font size="1" face="Arial">$&nbsp;<%=RS("OFRE1")%></font></td>
<td width="4%" align="center"><font size="1" face="Arial"><%=RS("DIA2")%></font></td>
<td width="4%" align="center"><font size="1" face="Arial">$&nbsp;<%=RS("OFRE2")%></font></td>
<td width="4%" align="center"><font size="1" face="Arial"><%=RS("DIA3")%></font></td>
<td width="4%" align="center"><font size="1" face="Arial">$&nbsp;<%=RS("OFRE3")%></font></td>
<td width="4%" align="center"><font size="1" face="Arial"><%=RS("DIA4")%></font></td>
<td width="4%" align="center"><font size="1" face="Arial">$&nbsp;<%=RS("OFRE4")%></font></td>
<td width="3%" align="center"><font size="1" face="Arial"><%=RS("DIA5")%></font></td>
<td width="4%" align="center"><font size="1" face="Arial">$&nbsp;<%=RS("OFRE5")%></font></td>
<td width="9%" align="center">&nbsp;</td>
<td width="9%" align="center">
<p align="left"><font face="Arial" size="1">$</font></p>

</td>

</tr>
<%Repeat1__index = Repeat1__index + 1
Repeat1__numRows = Repeat1__numRows - 1
RS.MoveNext
Wend%>
</table>

</body>

</html>
  #2 (permalink)  
Antiguo 20/02/2006, 12:01
Avatar de JJF
JJF
 
Fecha de Ingreso: mayo-2005
Mensajes: 205
Antigüedad: 20 años
Puntos: 0
el archivo del include

SCRIPX10/scripx10-cab.txt


<%
RS_numRows = 0
Dim Repeat1__numRows
Repeat1__numRows = 300
Dim Repeat1__index
Repeat1__index = 0
RS_numRows = RS_numRows + Repeat1__numRows
%>
<%
' *** Recordset Stats, Move To Record, and Go To Record: declare stats variables

' set the record count
RS_total = RS.RecordCount

' set the number of rows displayed on this page
If (RS_numRows < 0) Then
RS_numRows = RS_total
Elseif (RS_numRows = 0) Then
RS_numRows = 1
End If

' set the first and last displayed record
RS_first = 1
RS_last = RS_first + RS_numRows - 1

' if we have the correct record count, check the other stats
If (RS_total <> -1) Then
If (RS_first > RS_total) Then RS_first = RS_total
If (RS_last > RS_total) Then RS_last = RS_total
If (RS_numRows > RS_total) Then RS_numRows = RS_total
End If
%>
<%
' *** Recordset Stats: if we don't know the record count, manually count them

If (RS_total = -1) Then

' count the total records by iterating through the recordset
RS_total=0
While (Not RS.EOF)
RS_total = RS_total + 1
RS.MoveNext
Wend

' reset the cursor to the beginning
If (RS.CursorType > 0) Then
RS.MoveFirst
Else
RS.Requery
End If

' set the number of rows displayed on this page
If (RS_numRows < 0 Or RS_numRows > RS_total) Then
RS_numRows = RS_total
End If

' set the first and last displayed record
RS_first = 1
RS_last = RS_first + RS_numRows - 1
If (RS_first > RS_total) Then RS_first = RS_total
If (RS_last > RS_total) Then RS_last = RS_total

End If
%>
<%
' *** Move To Record and Go To Record: declare variables

Set MM_rs = RS
MM_rsCount = RS_total
MM_size = RS_numRows
MM_uniqueCol = ""
MM_paramName = ""
MM_offset = 0
MM_atTotal = false
MM_paramIsDefined = false
If (MM_paramName <> "") Then
MM_paramIsDefined = (Request.QueryString(MM_paramName) <> "")
End If
%>
<%
' *** Move To Record: handle 'index' or 'offset' parameter

if (Not MM_paramIsDefined And MM_rsCount <> 0) then

' use index parameter if defined, otherwise use offset parameter
r = Request.QueryString("index")
If r = "" Then r = Request.QueryString("offset")
If r <> "" Then MM_offset = Int(r)

' if we have a record count, check if we are past the end of the recordset
If (MM_rsCount <> -1) Then
If (MM_offset >= MM_rsCount Or MM_offset = -1) Then ' past end or move last
If ((MM_rsCount Mod MM_size) > 0) Then ' last page not a full repeat region
MM_offset = MM_rsCount - (MM_rsCount Mod MM_size)
Else
MM_offset = MM_rsCount - MM_size
End If
End If
End If

' move the cursor to the selected record
i = 0
While ((Not MM_rs.EOF) And (i < MM_offset Or MM_offset = -1))
MM_rs.MoveNext
i = i + 1
Wend
If (MM_rs.EOF) Then MM_offset = i ' set MM_offset to the last possible record

End If
%>
<%
' *** Move To Record: if we dont know the record count, check the display range

If (MM_rsCount = -1) Then

' walk to the end of the display range for this page
i = MM_offset
While (Not MM_rs.EOF And (MM_size < 0 Or i < MM_offset + MM_size))
MM_rs.MoveNext
i = i + 1
Wend

' if we walked off the end of the recordset, set MM_rsCount and MM_size
If (MM_rs.EOF) Then
MM_rsCount = i
If (MM_size < 0 Or MM_size > MM_rsCount) Then MM_size = MM_rsCount
End If

' if we walked off the end, set the offset based on page size
If (MM_rs.EOF And Not MM_paramIsDefined) Then
If (MM_offset > MM_rsCount - MM_size Or MM_offset = -1) Then
If ((MM_rsCount Mod MM_size) > 0) Then
MM_offset = MM_rsCount - (MM_rsCount Mod MM_size)
Else
MM_offset = MM_rsCount - MM_size
End If
End If
End If

' reset the cursor to the beginning
If (MM_rs.CursorType > 0) Then
MM_rs.MoveFirst
Else
MM_rs.Requery
End If

' move the cursor to the selected record
i = 0
While (Not MM_rs.EOF And i < MM_offset)
MM_rs.MoveNext
i = i + 1
Wend
End If
%>
<%
' *** Move To Record: update recordset stats

' set the first and last displayed record
RS_first = MM_offset + 1
RS_last = MM_offset + MM_size
If (MM_rsCount <> -1) Then
If (RS_first > MM_rsCount) Then RS_first = MM_rsCount
If (RS_last > MM_rsCount) Then RS_last = MM_rsCount
End If

' set the boolean used by hide region to check if we are on the last record
MM_atTotal = (MM_rsCount <> -1 And MM_offset + MM_size >= MM_rsCount)
%>
<%
' *** Go To Record and Move To Record: create strings for maintaining URL and Form parameters

' create the list of parameters which should not be maintained
MM_removeList = "&index="
If (MM_paramName <> "") Then MM_removeList = MM_removeList & "&" & MM_paramName & "="
MM_keepURL="":MM_keepForm="":MM_keepBoth="":MM_kee pNone=""

' add the URL parameters to the MM_keepURL string
For Each Item In Request.QueryString
NextItem = "&" & Item & "="
If (InStr(1,MM_removeList,NextItem,1) = 0) Then
MM_keepURL = MM_keepURL & NextItem & Server.URLencode(Request.QueryString(Item))
End If
Next

' add the Form variables to the MM_keepForm string
For Each Item In Request.Form
NextItem = "&" & Item & "="
If (InStr(1,MM_removeList,NextItem,1) = 0) Then
MM_keepForm = MM_keepForm & NextItem & Server.URLencode(Request.Form(Item))
End If
Next

' create the Form + URL string and remove the intial '&' from each of the strings
MM_keepBoth = MM_keepURL & MM_keepForm
if (MM_keepBoth <> "") Then MM_keepBoth = Right(MM_keepBoth, Len(MM_keepBoth) - 1)
if (MM_keepURL <> "") Then MM_keepURL = Right(MM_keepURL, Len(MM_keepURL) - 1)
if (MM_keepForm <> "") Then MM_keepForm = Right(MM_keepForm, Len(MM_keepForm) - 1)

' a utility function used for adding additional parameters to these strings
Function MM_joinChar(firstItem)
If (firstItem <> "") Then
MM_joinChar = "&"
Else
MM_joinChar = ""
End If
End Function
%>
<%
' *** Move To Record: set the strings for the first, last, next, and previous links

MM_keepMove = MM_keepBoth
MM_moveParam = "index"

' if the page has a repeated region, remove 'offset' from the maintained parameters
If (MM_size > 0) Then
MM_moveParam = "offset"
If (MM_keepMove <> "") Then
params = Split(MM_keepMove, "&")
MM_keepMove = ""
For i = 0 To UBound(params)
nextItem = Left(params(i), InStr(params(i),"=") - 1)
If (StrComp(nextItem,MM_moveParam,1) <> 0) Then
MM_keepMove = MM_keepMove & "&" & params(i)
End If
Next
If (MM_keepMove <> "") Then
MM_keepMove = Right(MM_keepMove, Len(MM_keepMove) - 1)
End If
End If
End If

' set the strings for the move to links
If (MM_keepMove <> "") Then MM_keepMove = MM_keepMove & "&"
urlStr = Request.ServerVariables("URL") & "?" & MM_keepMove & MM_moveParam & "="
MM_moveFirst = urlStr & "0"
MM_moveLast = urlStr & "-1"
MM_moveNext = urlStr & Cstr(MM_offset + MM_size)
prev = MM_offset - MM_size
If (prev < 0) Then prev = 0
MM_movePrev = urlStr & Cstr(prev)
%>


gracias por todo.
  #3 (permalink)  
Antiguo 20/02/2006, 14:48
Avatar de Myakire
Colaborador
 
Fecha de Ingreso: enero-2002
Ubicación: Centro de la república
Mensajes: 8.849
Antigüedad: 23 años, 3 meses
Puntos: 146
¿acaso alguien se tomará el tiempo de estudiar ese código?
  #4 (permalink)  
Antiguo 20/02/2006, 15:00
Avatar de ElAprendiz  
Fecha de Ingreso: enero-2002
Ubicación: Maipu, Chile
Mensajes: 3.706
Antigüedad: 23 años, 3 meses
Puntos: 2
iba a decir lo mismo. no abuses viejo....
__________________
Manual de ASP Avanzado ;-)
  #5 (permalink)  
Antiguo 20/02/2006, 17:36
Avatar de AlZuwaga
Colaborador
 
Fecha de Ingreso: febrero-2001
Ubicación: 34.517 S, 58.500 O
Mensajes: 14.550
Antigüedad: 24 años, 2 meses
Puntos: 535
yo me guardé el comentario anteriormente... pero ya que son 2, ahora somos 3
__________________
...___...
  #6 (permalink)  
Antiguo 20/02/2006, 17:48
Avatar de AlZuwaga
Colaborador
 
Fecha de Ingreso: febrero-2001
Ubicación: 34.517 S, 58.500 O
Mensajes: 14.550
Antigüedad: 24 años, 2 meses
Puntos: 535
Mmm... igual lo leí

(no todo )


Cita:
1: que un code me saque un promedio de las celdas "asis"
2: que un code me sume las celdas "of."
Te digo algo, mientras no seas más específico, es poco lo que se puede hacer.

Lo que pretendés promediar y sumar son datos de una base de datos, no celdas.
Intuyo que asis son los datos RS("DIA1") a RS("DIA5") y que of son los de RS("OFRE1") a RS("OFRE5")... pero como esos datos están en un WHILE ... WEND, pues como que no queda claro exactamente qué es lo que querés promediar y sumar.

Si querés promediar/sumar los datos de cada registro, así:

Código:
<%
promedio = (RS("DIA1") + RS("DIA2") + RS("DIA3") + RS("DIA4") + RS("DIA5")) / 5
suma = RS("OFRE1") + RS("OFRE2") + RS("OFRE3") + RS("OFRE4") + RS("OFRE5")
%>
Pero no creo que hayas preguntado algo tan básico como una simple suma y promedio como para que esta respuesta te sea de utilidad (supongo eso te lo enseñaron en las clases de matemáticas).

Reitero: Sé más específico
__________________
...___...
  #7 (permalink)  
Antiguo 20/02/2006, 18:12
Avatar de ElAprendiz  
Fecha de Ingreso: enero-2002
Ubicación: Maipu, Chile
Mensajes: 3.706
Antigüedad: 23 años, 3 meses
Puntos: 2
oye no eras el que me pidio ayuda sobre un viejo enlace sobre como promediar en javascript??

http://www.forosdelweb.com/f13/promediar-texbox-90714/

lo revisaste?
__________________
Manual de ASP Avanzado ;-)
  #8 (permalink)  
Antiguo 21/02/2006, 15:16
Avatar de JJF
JJF
 
Fecha de Ingreso: mayo-2005
Mensajes: 205
Antigüedad: 20 años
Puntos: 0
Sonrisa Muchachos, lo tengo.

Hice una mezcla terriblemente sencilla y logre los resultados que queria...
¿¿LES PASO EL CODIGO??? JAJAJAJAJA


Disculpen, fue un desliz de mi desesperación!
pero si lo quieren solicitenlo que no problem"

Gracias por cuestionarme!jajaja

Gracias Aprendiz, tu code está bueno pero no lo pude hacer funcionar poniendo un texbox en cada celda de una tabla, tienen que estar en una misma. PERO LO ACOMODE Y YA!



Juanjo
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 14:51.