ASP中函數調用對參數的影響

來源:互聯網
上載者:User

標籤:style   c   color   int   a   資料   

ASP中函數調用對參數的影響

在ASP編程中,經常需要自己編寫一些函數(或過程)來實現某些特定的功能,這時往往需要向函數(或過程)傳遞相應的參數 
在函數(或過程)中進行資料處理,即有可能需要保留或改變參數的值,下面有相關範例 
用下面的函數(TestAddress)就可以使一個函數多個返回值成為可能(一個函數返回值,多個參數改變後的值)

範例:

<%@LANGUAGE="VBSCRIPT"%> 
<% 
Option Explicit

‘=================================================================== 
‘ 參數傳遞 
‘ 1.值傳遞參數 (Call By Value) 
‘ Function TestValue(ByVal A,ByVal B) 
‘ 函數內參數 A、B 改變 不影響 函數的外部變數 
‘ 
‘ 2.指標參數 (Call By Address) 
‘ Function TestAddress(ByRef A,Byref B) 
‘ 函數內參數 A、B 改變 影響到 函數的外部變數 
‘ 
‘ 說明: 
‘ 1. 參數可以是數字、字元、數組、對象等VBSCRIPT語言所支援的大部分類型 
‘ 2. 函數返回值的類型也可以是數字、字元、數組、對象等VBSCRIPT語言所支援的大部分類型 
‘ 3. 程序呼叫參數方法與函數類似 
‘=================================================================== 
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 "初值:" & "&nbsp;" 
Response.Write "A1=" & A1 & "&nbsp;" 
Response.Write "B1=" & B1 & "<BR>" 
Response.Write "函數(TestValue)值:" & TestValue(A1,B1) & "<BR>" 
Response.Write "終值:" & "&nbsp;" 
Response.Write "A1=" & A1 & "&nbsp;" 
Response.Write "B1=" & B1 & "<BR><BR><BR>"

Response.Write "初值:" & "&nbsp;" 
Response.Write "A2=" & A2 & "&nbsp;" 
Response.Write "B2=" & B2 & "<BR>" 
Response.Write "函數(TestAddress)值:" & TestAddress(A2,B2) & "<BR>" 
Response.Write "終值:" & "&nbsp;" 
Response.Write "A2=" & A2 & "&nbsp;" 
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

‘ 類似,傳遞數組、對象(或者在函數中改變其值、屬性) 
’對象直接把對象名作為參數即可 
‘ 數組,把數組名稱作為參數

redim aryTest(2,2) 
dim intNum


function Ary_Test(ByRef A) 
Ary_Test = Ubound(Ary_Test,2) 
end function

‘調用

intNum = Ary_Test(intNum) ‘值為 3

%> 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.