案例源码 asp 函数调用返回多个值处理方法
1. 数组方式返回多个值
<%
'dim getarr
dim temp, ele
temp="a,b,c,d,e"
function fRtMltVal(str)
'dim rearr(3)
'rearr(0)="12312"
fRtMltVal=split(str,",")
'或者fRtMltVal=rearr
end function
for each ele in fRtMltVal(temp)
response.write ele&"<br/>"
next 'u als kn chc mlt ar //shawl.qiu
'getarr=fRtMltVal(temp)
'response.write getarr(0)
%>
2. 类方式返回多个值
<%
class cVnt
public val
public val1
end class
function fRtMltVal()
set fRtMltVal= new cVnt
fRtMltVal.val="...val..."
fRtMltVal.val1="...val1..."
end function 'shawl.qiu code
response.write fRtMltVal.val&"<br/>"&fRtMltVal.val1
%>
3. 字典方式返回多个值
<%
function fRtMltVal()
set dic=createObject("scripting.dictionary")
dic.add "val", "...val"
dic.add "val1", "...val1"
dic.add "val2", "...val2"
set fRtMltVal=dic
end function : dim dic 'shawl.qiu code
set dic= fRtMltVal()
response.write dic("val")&"<br/>"
response.write dic("val1")&"<br/>"
response.write dic("val2")
set dic=nothing
%>
4. asp中的Function 是有返回值的,要调用的时候需要加call 或者 dim a a=Fname(str)
sub 是表示不需要返回值的!
5.如果是使用ram
randomize
ramnum=int((999999 - 111111 + 1) * Rnd + 111111)
‘范围在11111-999999之间的整数
6、直接参数赋值判断
Function finance(ddh,mark)
Dim ysje : ysje=0'应收金额
Dim ssje : ssje=0'实收金额
Dim zcje : zcje=0'支出金额
Dim jyje : jyje=0'结余金额
Dim rs
set rs=server.CreateObject("ADODB.recordset")
Dim cmd
cmd="select * from mos_good_yw where ddh_good='"&ddh&"'"
rs.open cmd,conn,1,3
do while not rs.eof
ysje=ysje+cint(rs("price_good"))
ssje=ssje+cint(rs("sjje_good"))
zcje=zcje+cint(rs("zc_good"))
if not rs.eof then rs.movenext
loop
rs.close
set rs=nothing
jyje=ssje-zcje
Dim m
m=mark
select case m
case 1
finance=ysje
case 2
finance=ssje
case 3
finance=zcje
case 4
finance=jyje
end select
End Function
我们就以asp教程来举例说明关于,如何在用户自定义函数调用时反回多的值,先来看一组代码
<%
call getmynumber(aa,bb,cc)
response.write aa & " " & bb & "<br />" & cc
function getmynumber(byref aa,byref bb,byref cc)
aa=3
bb=4
cc =10
end function
%> 这里是利用了byref再看详细的
sub test(byref a as integer, byval b as integer)
a = 3
b = 4
end sub
sub main()
dim a as integer
dim b as integer
a = 1
b = 2
test a, b
msgbox "a=" & a & ";b=" & b
end sub
输出结果 a=3;b=2byref作用是存址参数,通过操作参数的内存地址实现全局控制,