Results 1 to 7 of 7

Thread: With or without parenthesis?

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2012
    Posts
    35

    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.
    Last edited by jalexm; Apr 12th, 2012 at 03:05 PM.

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    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)

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2012
    Posts
    35

    Re: With or without parenthesis?

    Quote Originally Posted by RhinoBull View Post
    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?

  4. #4
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: With or without parenthesis?

    Quote Originally Posted by jalexm View Post
    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).
    Last edited by dilettante; Apr 12th, 2012 at 09:51 PM.

  5. #5

  6. #6

    Thread Starter
    Member
    Join Date
    Feb 2012
    Posts
    35

    Re: With or without parenthesis?

    Quote Originally Posted by dilettante View Post
    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 View Post
    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

  7. #7
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,969

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width