Function call and parameter transfer in VB

Source: Internet
Author: User

Parentheses must be added for an array.

For example, the sub EM (pay () as single) process is defined)

Calling process EM (Xu ())

Pass by value (byval): The parameters and real parameters occupy different buckets. The value of the parameter variable is changed during the call process, and the value of the real parameter is not affected. After the call is complete, the real parameter is still the value before the call,

Private sub commandementclick ()

Dim X as integer

X = 6

Print "before the sub process is called X ="; x

Call test (X)

Print "x ="; x

End sub

Sub test (byval M as integer)

M = m + 5

End sub

 

 

Pass by address (byref, Default Transfer Method): During the call process, the address of the real parameter variable is passed to the form parameter and the same address is used. Therefore, the same data type is used. Only when the real parameter is a variable or array can it be passed by address, if it is a constant, it is actually passed by value.

Private sub commandementclick ()

Dim X as integer

X = 6

Print "before the sub process is called X ="; x

Call test (X)

Print "x ="; x

End sub

Sub test (byref M as integer)

M = m + 5

End sub

 

Parameters are transmitted by address when an array is used as parameters. The keyword "byval" cannot be used to modify the parameters.

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.