ASP中函數(shù)調(diào)用對(duì)參數(shù)的影響
發(fā)表時(shí)間:2023-08-14 來源:明輝站整理相關(guān)軟件相關(guān)文章人氣:
[摘要]在ASP編程中,經(jīng)常需要自己編寫一些函數(shù)(或過程)來實(shí)現(xiàn)某些特定的功能,這時(shí)往往需要向函數(shù)(或過程)傳遞相應(yīng)的參數(shù)在函數(shù)(或過程)中進(jìn)行數(shù)據(jù)處理,即有可能需要保留或改變參數(shù)的值,下面有相關(guān)范例用下面...
在ASP編程中,經(jīng)常需要自己編寫一些函數(shù)(或過程)來實(shí)現(xiàn)某些特定的功能,這時(shí)往往需要向函數(shù)(或過程)傳遞相應(yīng)的參數(shù)
在函數(shù)(或過程)中進(jìn)行數(shù)據(jù)處理,即有可能需要保留或改變參數(shù)的值,下面有相關(guān)范例
用下面的函數(shù)(TestAddress)就可以使一個(gè)函數(shù)多個(gè)返回值成為可能(一個(gè)函數(shù)返回值,多個(gè)參數(shù)改變后的值)
范例:
<%@LANGUAGE="VBSCRIPT"%>
<%
Option Explicit
'===================================================================
' 參數(shù)傳遞
' 1.值傳遞參數(shù) (Call By Value)
' Function TestValue(ByVal A,ByVal B)
' 函數(shù)內(nèi)參數(shù) A、B 改變 不影響 函數(shù)的外部變量
'
' 2.指針參數(shù) (Call By Address)
' Function TestAddress(ByRef A,Byref B)
' 函數(shù)內(nèi)參數(shù) A、B 改變 影響到 函數(shù)的外部變量
'
' 說明:
' 1. 參數(shù)可以是數(shù)字、字符、數(shù)組、對(duì)象等VBSCRIPT語言所支持的大部分類型
' 2. 函數(shù)返回值的類型也可以是數(shù)字、字符、數(shù)組、對(duì)象等VBSCRIPT語言所支持的大部分類型
' 3. 過程調(diào)用參數(shù)方法與函數(shù)類似
'===================================================================
Dim A1,B1
Dim A2,B2
Function TestValue(ByVal A,ByVal B)
A = A + 1
B = B + 1
TestValue = A + B
End Function
Function TestAddress(ByRef A,Byref B)
A = A + 1
B = B + 1
TestAddress = A + B
End Function
A1 = 11
B1 = 33
A2 = 11
B2 = 33
Response.Write "初值:" & " "
Response.Write "A1=" & A1 & " "
Response.Write "B1=" & B1 & "<BR>"
Response.Write "函數(shù)(TestValue)值:" & TestValue(A1,B1) & "<BR>"
Response.Write "終值:" & " "
Response.Write "A1=" & A1 & " "
Response.Write "B1=" & B1 & "<BR><BR><BR>"
Response.Write "初值:" & " "
Response.Write "A2=" & A2 & " "
Response.Write "B2=" & B2 & "<BR>"
Response.Write "函數(shù)(TestAddress)值:" & TestAddress(A2,B2) & "<BR>"
Response.Write "終值:" & " "
Response.Write "A2=" & A2 & " "
Response.Write "B2=" & B2
'======================
' 相似過程
'======================
Sub Test_Value(ByVal A,ByVal B)
A = A + 1
B = B + 1
End Sub
Sub Test_Address(ByRef A,Byref B)
A = A + 1
B = B + 1
End Sub
%>