VBScript learning notes-functions and subroutines

Source: Internet
Author: User

I. Definition 1. Function Definition:
function f_add(num_in)    num_in = num_in + 1    f_add = num_inend function

Return parameters using the function name

2. subroutine Definition
sub s_add(num_in)    num_in = num_in + 1end sub

No return value for the subroutine

Ii. Differences between functions and child routines in parameter passing

You can specify parameters in brackets or use a format that does not contain parentheses.

When a parameter is specified in parentheses, the parameter is passed by value. Modifications to the parameter in a function or subroutine are not reflected in the parameter. When the parameter format is not in parentheses, changes to the parameter values in the function or subroutine are actually made.

The following code demonstrates the differences between the two formats:

num_out = 0wscript.echo "num before sub:", num_out‘用不带括号的格式调用子例程s_add num_outwscript.echo "num after sub:", num_outwscript.echo ""num_out = 0wscript.echo "num before sub():", num_out‘用带括号的格式调用子例程s_add(num_out)wscript.echo "num after sub():", num_outwscript.echo ""num_out = 0wscript.echo "num before function:", num_out‘用不带括号的格式调用函数f_add num_outwscript.echo "num after function:", num_outwscript.echo ""num_out = 0wscript.echo "num before function():", num_out‘用带括号的格式调用函数f_add(num_out)wscript.echo "num after function():", num_outwscript.echo ""sub s_add(num_in)    wscript.echo "num in sub", num_in    num_in = num_in + 1    wscript.echo "num in sub", num_inend subfunction f_add(num_in)    wscript.echo "num in function", num_in    num_in = num_in + 1    wscript.echo "num in function", num_in    f_add = num_inend function

The output result is as follows:


Num before Sub: 0
Num in sub 0
Num in sub 1
Num after Sub: 1

Num before sub (): 0
Num in sub 0
Num in sub 1
Num after sub (): 0

Num before function: 0
Num in function 0
Num in function 1
Num after function: 1

Num before function (): 0
Num in function 0
Num in function 1
Num after function (): 0

VBScript learning notes-functions and subroutines

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.