| 发表于:2007-03-17 19:31:503楼 得分:0 |
看起来太累了. 是这我以前写的购物车用到的自定义函数. 直接套用吧. public sub createcart() if isarray(session( "cart ")) = false then dim arycart() redim arycart(5,0) session( "cart ") = arycart end if end sub function checkcart() if isarray(session( "cart ")) then checkcart = true else checkcart = false end if end function function checkitem(id) dim arycart,findflag,i if checkcart = true then arycart = session( "cart ") findflag=false for i = lbound(arycart,2) to ubound(arycart,2) if clng(arycart(0,i)) = id then findflag=true exit for end if next checkitem = findflag end if end function public sub removeitem(id) if not checkitem(id) then exit sub end if dim i,intpos,arycart,newsize arycart = session( "cart ") for i = lbound(arycart,2) to ubound(arycart,2) if cint(arycart(0,i)) = id then intpos = i exit for end if next for i = intpos to ubound(arycart,2)-1 if not arycart(0,i) = " " then arycart(0,i) = arycart(0,i+1) arycart(1,i) = arycart(1,i+1) arycart(2,i) = arycart(2,i+1) arycart(3,i) = arycart(3,i+1) arycart(4,i) = arycart(4,i+1) arycart(5,i) = arycart(5,i+1) end if next newsize=ubound(arycart,2)-1 redim preserve arycart(5,newsize) session( "cart ") = arycart end sub public sub updateitem(id,num) dim aryupdatecart,i aryupdatecart = session( "cart ") for i = lbound(aryupdatecart,2) to ubound(aryupdatecart,2) if cint(aryupdatecart(0,i)) = id then aryupdatecart(5,i) = num session( "cart ") = aryupdatecart exit for end if next end sub public sub additem(id,num) dim btncartstatus,aryaddcart,newsize,i btncartstatus = checkcart if btncartstatus = false then createcart set rs=fs.EXECute( "select productname,picture,shi_price,hao_price from fs_product where id= "&id) aryaddcart = session( "cart ") aryaddcart (0,0) = id aryaddcart (1,0) = rs( "productname ") aryaddcart (2,0) = rs( "picture ") aryaddcart (3,0) = rs( "shi_price ") aryaddcart (4,0) = rs( "hao_price ") aryaddcart (5,0) = num session ( "cart ") = aryaddcart set rs=nothing exit sub elseif btncartstatus = true then if checkitem(id) = true then aryaddcart = session( "cart ") for i = lbound(aryaddcart,2) to ubound(aryaddcart,2) if cint(aryaddcart(0,i)) = id then aryaddcart(5,i) = aryaddcart(5,i)+num session( "cart ") = aryaddcart exit for end if next elseif checkitem(id) = false then aryaddcart = session( "cart ") newsize=ubound(aryaddcart,2)+1 redim preserve aryaddcart(5,newsize) set rs=fs.EXECute( "select productname,picture,shi_price,hao_price from fs_product where id= "&id) aryaddcart(0,newsize) = id aryaddcart(1,newsize) = rs( "productname ") aryaddcart(2,newsize) = rs( "picture ") aryaddcart(3,newsize) = rs( "shi_price ") aryaddcart(4,newsize) = rs( "hao_price ") aryaddcart(5,newsize) = num session( "cart ") = aryaddcart set rs=nothing exit sub end if end if end sub | | |
|