The effect of function invocation on parameters in ASP

Source: Internet
Author: User
Tags final variables
In ASP programming, it is often necessary to write some functions (or procedures) to implement certain functions, which often need to pass the corresponding parameters to the function (or procedure)
In a function (or procedure) of data processing, that is, there may be a need to retain or change the value of the parameter, the following are the relevant examples
The following function (testaddress) makes it possible to have multiple return values for a function (a function returns a value, a value that is changed by multiple parameters)

Example:

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

'===================================================================
' Parameter passing
' 1. Value pass parameter (call by value)
' Function testvalue (ByVal a,byval B)
' The parameter A, B changes in the function does not affect the external variables of the function
'
' 2. Pointer parameter (call to address)
' Function testaddress (ByRef a,byref B)
' The parameter A and B changes in the function affect the external variables of the function
'
Description
' 1. Parameters can be numbers, characters, arrays, objects, and most of the types supported by the VBScript language
' 2. The type of the function return value can also be a number, character, array, object, and so on most types supported by the VBScript language
' 3. Procedure Call parameter method is similar to function
'===================================================================
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 "Initial value:" & ""
Response.Write "a1=" & A1 & ""
Response.Write "b1=" & B1 & "<BR>"
Response.Write "Function (TestValue) value:" & TestValue (A1,B1) & "<BR>"
Response.Write "Final value:" & ""
Response.Write "a1=" & A1 & ""
Response.Write "b1=" & B1 & "<BR><BR><BR>"

Response.Write "Initial value:" & ""
Response.Write "A2=" & A2 & ""
Response.Write "B2=" & B2 & "<BR>"
Response.Write "Function (testaddress) value:" & Testaddress (A2,B2) & "<BR>"
Response.Write "Final value:" & ""
Response.Write "A2=" & A2 & ""
Response.Write "B2=" & B2

'======================
' Similar process
'======================
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

%>


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.