There are two ways to declare formal parameters in VB, one is ByVal and the other is ByRef. If it is ByVal, a copy of the actual parameter will be passed to the subroutine when passing the parameter. Modification of the parameter by the subroutine will not affect the original parameter. If it is ByRef, the pointer of the actual parameter is passed to the subroutine, and the modification of the parameter by the subroutine will affect the value of the original parameter.
| File name: | ByVal.asp | ByRef.asp |
| Specific code: | <% SubTestMain() Dim A : A=5 Call TestBy(A) Response.write A End Sub Sub TestBy(ByVal T) T=T+1 End sub call TestMain() %> | <% SubTestMain() Dim A : A=5 Call TestBy(A) Response.write A End Sub Sub TestBy(ByRef T) T=T+1 End sub callTestMain() %> |
| Running results: | 5 | 6 |
| in conclusion: | Note: The declaration method of T variable in subroutine TestBy(ByVal T) is ByVal Running the result subroutine does not affect the value of A | Note: The declaration method of T variable in subroutine TestBy(ByRef T) is ByRef The value of running result A has changed through the subroutine |