(reproduced) The difference between ByVal and ByRef in VB

Source: Internet
Author: User

ByVal is transmitted by value , the original value is not changed during the pass, and only a copy is transmitted.

Instead of ByRef , the latter is the same memory address from the memory address.

ByVal and ByRef (default value)
These two are the parameters passed by the child procedure when the parameters are passed by the specified
ByVal (passed by value)
ByRef (delivered by address)

See the following example for details:

Dim A as integer,b as Integer
A=1
b=2
Call Fun01 (A, B)
The result of Print A, B ' is 2 3 (the change in the parameters affects the argument, i.e. now A=2,B=3)
Call Fun02 (A, B)
Pring A, B ' gets the same result as above, 2 3 (the change of the parameter does not affect this argument)

Sub Fun01 (I as integer,j as Integer) ' default, the address is passed
I=i+1
J=j+1
End Sub

Sub fun02 (ByVal I as Integer,byval J as Integer) ' passed by value
I=i+1
J=j+1
End Sub

(reproduced) The difference between ByVal and ByRef in VB

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.