asp中求和
有一条记录的某字段值为:10,20,30,.....数值个数是动态的。我怎样才能把该字段值输出累加求和。...
有一条记录的某字段值为:10,20,30,.....数值个数是动态的。我怎样才能把该字段值输出累加求和。
展开
2个回答
展开全部
根据题意,ASP VBScript应该是
dim Num,x,Sum
Num = "10,20,30,40,50"
Sum = 0
Num = Split(Num,",")
If IsArray(Num) then
For x = 0 to Ubound(Num)
Sum = Sum + Int(Num(x))
Next
End if
response.Write Sum
=====================================
如果是数据库中多记录求和则直接用sql
select Sum(该字段) from 该表
=====================================
js的
var Num = "1,2,3,4,5",Sum = 0;
Num = Num.split(",");
for ( var x = 0 ; x < Num.length ; x++ ) {
Sum += parseInt(Num[x]);
}
document.write(Sum);
dim Num,x,Sum
Num = "10,20,30,40,50"
Sum = 0
Num = Split(Num,",")
If IsArray(Num) then
For x = 0 to Ubound(Num)
Sum = Sum + Int(Num(x))
Next
End if
response.Write Sum
=====================================
如果是数据库中多记录求和则直接用sql
select Sum(该字段) from 该表
=====================================
js的
var Num = "1,2,3,4,5",Sum = 0;
Num = Num.split(",");
for ( var x = 0 ; x < Num.length ; x++ ) {
Sum += parseInt(Num[x]);
}
document.write(Sum);
展开全部
你是想用哪种语言求和呢?javascript还是vbscript?
javascript这样写:
<script language="javascript">
<!--
function abc(a)
{
var x=0;
var he=new Array(a);
for (i=0;i<he.length;i++)
{
var j;
j=i+1;
he[i]=j*10;
x+=he[i];
}
return x;
}
document.write(abc(3)); //abc()的参数就是数组个数,随便你写啦
-->
</javascript>
vbscript在ASP中这样写:
<%
function abc(a)
dim b
for i=1 to a
b=b+i*10
next
abc=b
end function
response.Write(abc(3))
%>
javascript这样写:
<script language="javascript">
<!--
function abc(a)
{
var x=0;
var he=new Array(a);
for (i=0;i<he.length;i++)
{
var j;
j=i+1;
he[i]=j*10;
x+=he[i];
}
return x;
}
document.write(abc(3)); //abc()的参数就是数组个数,随便你写啦
-->
</javascript>
vbscript在ASP中这样写:
<%
function abc(a)
dim b
for i=1 to a
b=b+i*10
next
abc=b
end function
response.Write(abc(3))
%>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询