Is it possible to call a VB function without the parenthesis?

前端 未结 4 391
-上瘾入骨i
-上瘾入骨i 2021-01-03 07:17

I am looking at VB6 code and I see a statement as follows -

       Public Sub CheckXYZ(abc As Integer)

       If abc <> pqr Then SetVars abc
<         


        
4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-03 08:15

    This is a feature of VB6 (one which gladly was taken away in VB.NET) and is legal syntax.

    However I would not recommend using it because it can make the code more difficult to read and as @GTG pointed out can force ByVal when the method declaration is ByRef if you are not careful.

    (See the MS Documentation about this here)

    As such my advice is to always use the parentheses. If you see a space between the method name and the first bracket like this:

    SomeSubName (abc)

    This alerts you to the fact that something is wrong (i.e. abc if being forced to be passed ByVal) so you need to use Call and the space will be removed:

    Call SomeSubName(abc)

    This makes all your method calls consistent within your code.

    In the rare circumstances where you want to force abc to be passed ByVal you can do this which makes it much more obvious:

    Call SomeSubName((abc))

提交回复
热议问题