vba - Call关键字在VB6中起什么作用?

标签 vba vb6 syntax

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

Private Sub Method1()
    Call InnerMethod
End Sub

Private Sub Method2()
    InnerMethod
End Sub

Private Sub InnerMethod()
    '' stuff
End Sub

与Method2相比,使用Method1有什么优势?

最佳答案

MSDN:

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

在即时窗口中,如果输入
Proc1

然后打印“Hello World”。如果输入
Call Proc1

然后打印“Hello World”。如果输入
Proc2 "World"

然后打印“Hello World”。如果输入
Call Proc2 "World" 

您会收到一个编译错误。您必须输入
Call Proc2("World")

关于vba - Call关键字在VB6中起什么作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/479891/

相关文章:

vba - Excel VBA : Can I simply extend a range by one?

excel - 按三个单独的列对数据进行排序

json - 如何修复 XML HTTP 请求中的 "Subscript out of range"错误

windows-8 - VB6应用程序通过winsock发送UDP广播消息 - 仅每隔一条消息发送一次

vba - 检查值是否存在于范围内而不循环

vb6 - 部署使用 QuickBooks SDK 创建的应用程序

c++ - c++ 函数末尾的这是什么,...)

objective-c - 这是什么 Objective-C 语法,椭圆样式的点符号? "..."

javascript - 作用域的动态变量名

ide - 文件 -> Make... 菜单选项在 VB6 IDE 中被禁用