With or without parenthesis?
Hello.
I really don't know what the difference (if so) between using or not using parenthesis in sub/function calls. For example:
Compute x, y
or
Compute (x, y)
What's the difference?
Thanks.
Re: With or without parenthesis?
If procuedure doesn't return anything then don't use parenthesis:
Code:
Public Sub Test(x As Integer, y As Integer)
Me.Move x, y
End Sub
'sample usage
Test 1000, 1000
When procedure (function) returns value then syntax is a bit different:
Code:
Public Function Test(x As Integer, y As Integer) As Long
Test = x + y
End Function
'sample usage
Dim res As Long
res = Test(100, 200)
Re: With or without parenthesis?
Quote:
Originally Posted by
RhinoBull
If procuedure doesn't return anything then don't use parenthesis:
Code:
Public Sub Test(x As Integer, y As Integer)
Me.Move x, y
End Sub
'sample usage
Test 1000, 1000
But what about calling Test sub using parenthesis?
Test (1000, 1000)
Compiler doesn´t show any error. Is the same as not using parenthesis?
Re: With or without parenthesis?
Quote:
Originally Posted by
jalexm
But what about calling Test sub using parenthesis?
Test (1000, 1000)
Compiler doesn´t show any error. Is the same as not using parenthesis?
It sure results in an error here!
I'm beginning to think you are in the wrong forum and asking about VB.Net and not the original VB (6.0 and earlier).
Re: With or without parenthesis?
I agree with dilettante: in VB6 you should get a compile error "Expected: =".
What version of Visual Basic do you actually use?
Re: With or without parenthesis?
Quote:
Originally Posted by
dilettante
It sure results in an error here!
I'm beginning to think you are in the wrong forum and asking about VB.Net and not the original VB (6.0 and earlier).
Quote:
Originally Posted by
RhinoBull
I agree with dilettante: in VB6 you should get a compile error "Expected: =".
What version of Visual Basic do you actually use?
You are totally right. It was my mistake. Sorry :blush:
Re: With or without parenthesis?
You can do this:
Code:
Private Sub Form_Load()
Call Test(1000, 1000)
End Sub
Public Sub Test(x As Integer, y As Integer)
Me.Move x, y
End Sub