我们的项目中有一些代码看起来像这样:
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/