VB6 中的 Call 关键字有什么作用? [英] What does the Call keyword do in VB6?

查看:36
本文介绍了VB6 中的 Call 关键字有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的项目中有一些代码看起来像这样:

There's some code in our project that looks a bit like this:

Private Sub Method1()
    Call InnerMethod
End Sub

Private Sub Method2()
    InnerMethod
End Sub

Private Sub InnerMethod()
    '' stuff
End Sub

方法 1 与方法 2 相比有什么优势?

What's the advantage of doing Method1 over Method2?

推荐答案

来自 MSDN:

您不需要使用呼叫调用过程时的关键字.但是,如果您使用 Call 关键字调用一个需要的过程参数,参数列表必须是括在括号中.如果省略Call 关键字,您也必须省略参数列表周围的括号.如果您使用 Call 语法来调用任何内在的或用户定义的函数,函数的返回值被丢弃.

You are not required to use the Call keyword when calling a procedure. However, if you use the Call keyword to call a procedure that requires arguments, argumentlist must be enclosed in parentheses. If you omit the Call keyword, you also must omit the parentheses around argumentlist. If you use either Call syntax to call any intrinsic or user-defined function, the function's return value is discarded.

例如:

Sub Proc1()
    Debug.Print "Hello World"
End Sub

Sub Proc2(text As String)
    Debug.Print "Hello " & text
End Sub

在直接窗口中,如果你输入

In the immediate window, if you enter

Proc1

然后打印Hello World".如果你输入

then "Hello World" prints. If you enter

Call Proc1

然后打印Hello World".如果你输入

then "Hello World" prints. If you enter

Proc2 "World"

然后打印Hello World".如果你输入

then "Hello World" prints. If you enter

Call Proc2 "World" 

你得到一个编译错误.你必须输入

you get a compile error. You would have to enter

Call Proc2("World")

这篇关于VB6 中的 Call 关键字有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆