Is it possible to call a VB function without parentheses?

I look at the VB6 code, and I see the instruction as follows:

       Public Sub CheckXYZ(abc As Integer)

       If abc <> pqr Then SetVars abc

And when I click on the definition in SetVars, I move on to the next definition

      Private Sub SetVars(i As Integer)

I am new to VB. Is it something in common in VB to call function calls without parenthesis?

+3
source share
4 answers

As Ryan noted, parentheses should only be used when calling a function that returns a value.

One mistake I would like to add is that if you really DO NOT use the parent names inadvertently when calling Sub, VB6 will pass the parameter by value, not by reference.

If Sub has more than one parameter, this is not a risk, since this is illegal syntax in VB6:

SomeFunc (arg1, arg2)

But consider this example:

Sub AddOne(ByRef i As Integer)
  i = i + 1
End Sub

Sub Command1_Click()
  Dim i as Integer

  i = 1
  AddOne i    'i will be passed by reference and increased by 1
  Msgbox i    'Will print "2"
  AddOne (i)  'i will be passed by value, so the return value will be lost!!
  MsgBox i    'Will still print "2"!!
End Sub

, , .

+7

VB6 (, VB.NET) .

, , , @GTG, ByVal, ByRef, .

(. MS )

, - . , :

SomeSubName (abc)

, - (, abc, ByVal), Call, :

Call SomeSubName(abc)

.

, abc ByVal, , :

Call SomeSubName((abc))

+4

. Paranthesis , .

Private Sub Testy1()
    Function1 "Testy2" ' does not require parenthesis
    Debug.Print Function1("Testy3") ' does require parenthesis
End Sub

Private Function Function1(str as String) as Boolean
    Function1 = True
End Function
+2

I personally do not use or recommend using the Call operator. I personally find that paranas with functions and their lack with submaterials effectively differentiate the two. However, I really like Label's use of the call operator / byval / double parens. On rare occasions, when you want it, it makes it different even from any other call, if that is the only place you use the Call statement. I am going to use this if I live long enough to need it. :)

0
source

All Articles