数组项目的统计方法(Array Statistics)如下:

查询 日期(2007-12-2)

找到三条记录如下:

记录1服务项目字段值:|花门|鲜花|水晶灯|花车|地毯
记录1服务项目数量值:|2|10|2|1|5 // ( 2 , 10 , 2 , 1 , 5)
记录2服务项目字段值:|礼炮|鲜花|拱门|花车
记录2服务项目数量值:|4|10|2|1 //( 4 , 10 , 2 , 1)
记录3服务项目字段值:|花门|衣服|花车|地毯
记录3服务项目数量值:|1|2|1|5 //( 1 , 2 , 1 , 5)

现我统计上面记录服务项目名与数量


输出

花门:3
鲜花:20
水晶灯:2
花车:3
地毯:10
礼炮:4
拱门:2
衣服:2

感谢Csdn的Showbo的帮助:

option explicit
function hasAdd(L,N)
dim j
for j=0 to ubound(L)
if L(j) = N then
hasAdd=j’返回名称所处下标
exit function
end if
next
hasAdd=-1
end function

function Compute(data1,data2,First)
dim ds1,ds2
dim Max,i,Index
ds1=split(data1,”|”)
ds2=split(data2,”|”)
Max=ubound(ds1)
if First=true then
redim Lists(Max),Totals(Max)
for i=0 to Max
Lists(i)=ds1(i)
Totals(i)=cint(ds2(i))
next
exit function
end if
for i=0 to Max
Index=hasAdd(Lists,ds1(i))
if Index=-1 then
dim ListMax:ListMax=ubound(Lists)
redim Preserve Lists(ListMax+1)
redim Preserve Totals(ListMax+1)
Lists(ListMax+1)=ds1(i)
Totals(ListMax+1)=cint(ds2(i))
else
Totals(Index)=Totals(Index)+cint(ds2(i))
end if
next
end function

dim Lists(),Totals()

Compute “花门|鲜花|水晶灯|花车|地毯”,”2|10|2|1|5″,true

Compute “礼炮|鲜花|拱门|花车”,”4|10|2|1″,false

Compute “花门|衣服|花车|地毯”,”1|2|1|5″,false

dim j
for j=0 to ubound(Lists)
response.Write Lists(j)&”:”&Totals(j)&”<br/>”
next

后经自己修改完成所要效果.

function hasAdd(L,N)
dim j
for j=0 to ubound(L)
if L(j) = N then
hasAdd=j’返回名称所处下标
exit function
end if
next
hasAdd=-1
end function

function Compute(data1,data2,First)
dim ds1,ds2
dim Max,i,Index
ds1=split(data1,”|”)
ds2=split(data2,”|”)
Max=ubound(ds1)
if First=true then
redim Lists(Max),Totals(Max)
for i=0 to Max
Lists(i)=ds1(i)
Totals(i)=cint(ds2(i))
next
exit function
end if
for i=0 to Max
Index=hasAdd(Lists,ds1(i))
if Index=-1 then
dim ListMax:ListMax=ubound(Lists)
redim Preserve Lists(ListMax+1)
redim Preserve Totals(ListMax+1)
Lists(ListMax+1)=ds1(i)
Totals(ListMax+1)=cint(ds2(i))
else
Totals(Index)=Totals(Index)+cint(ds2(i))
end if
next
end function

Dim Rs,Sql,cnnum,a(),b(),cni
If Request.Form(”fwxmkey”) = “” Or isdate(Request.Form(”fwxmkey”)) = False Then Call Alert(”关键词必须填写日期!”,-1):Response.End()
     Sql = “Select fwxm,sl From Orders where hq=#” & Request.Form(”fwxmkey”) & “# order by id desc”
Response.Write(Sql)
     ‘Response.End()
     Call Indelup2(Sql,1,1)
     cnnum = Rs.recordcount
redim a(cnnum)
redim b(cnnum)
     Do While not Rs.eof
     a(cni) = mid(Rs(”fwxm”),2,len(Rs(”fwxm”))-1)
         b(cni) = mid(Rs(”sl”),2,len(Rs(”sl”))-1)
         Rs.movenext
     cni = cni + 1
     Loop

dim Lists(),Totals()

Response.Write(ubound(a) & “<br/><br/>”)
For ok = 0 to ubound(a)
If ok = 0 Then typ = true Else typ = false
Compute a(ok),b(ok),typ
next

for j=0 to ubound(Lists)
response.Write Lists(j)&”:”&Totals(j)&”<br/>”
next

谷歌搜索:数组项目的统计方法
百度搜索:数组项目的统计方法
雅虎搜索:数组项目的统计方法
搜狗搜索:数组项目的统计方法
搜搜搜索:数组项目的统计方法

,

Del.icio.us Google书签 Digg Live Bookmark Technorati Furl Yahoo书签 Facebook 百度搜藏 新浪ViVi 365Key网摘 天极网摘 和讯网摘 博拉网 POCO网摘 添加到饭否 QQ书签 Digbuzz我挖网

Leave a reply?