zoukankan      html  css  js  c++  java
  • VBScript学习笔记

    一、定义

    1. 函数定义:

    function f_add(num_in)
        num_in = num_in + 1
        f_add = num_in
    end function

    用函数名来返回参数

    2. 子例程定义

    sub s_add(num_in)
        num_in = num_in + 1
    end sub

    子例程没有返回值

    二、函数与子例程在参数传递上的差别

    函数和子例程调用时可以有两种方式:在括号中指定参数,或使用不带括号的格式。

    使用带括号的方式指定参数时,参数是按值传递的,函数或子例程中对参数的修改不会反映到参数中。而用不带括号的格式时,则函数或子例程中对参数值的改动都是实际发生的。

    以下代码示范了这两种格式的差别:

    num_out = 0
    wscript.echo "num before sub:", num_out
    '用不带括号的格式调用子例程
    s_add num_out
    wscript.echo "num after sub:", num_out
    wscript.echo ""
    
    num_out = 0
    wscript.echo "num before sub():", num_out
    '用带括号的格式调用子例程
    s_add(num_out)
    wscript.echo "num after sub():", num_out
    wscript.echo ""
    
    num_out = 0
    wscript.echo "num before function:", num_out
    '用不带括号的格式调用函数
    f_add num_out
    wscript.echo "num after function:", num_out
    wscript.echo ""
    
    num_out = 0
    wscript.echo "num before function():", num_out
    '用带括号的格式调用函数
    f_add(num_out)
    wscript.echo "num after function():", num_out
    wscript.echo ""
    
    sub s_add(num_in)
        wscript.echo "num in sub", num_in
        num_in = num_in + 1
        wscript.echo "num in sub", num_in
    end sub
    
    function 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_in
    end function

    输出结果如下


    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

  • 相关阅读:
    ubuntu 9.04更新源
    想学一下asp.net,跟着书本做了个bbs
    [转]ubuntu系统中遇到的一些问题及解决
    第一篇,打个招呼
    人际交往的书籍推荐
    程序员的五层境界,你在哪一层?
    HTTP报文之"请求报文"和"响应报文"详解
    如何提高你的工作效率?
    面对焦虑我们怎么办 ?
    CEO要看的书籍推荐
  • 原文地址:https://www.cnblogs.com/DigiK0ne/p/4015145.html
Copyright © 2011-2022 走看看