+ Reply to Thread
Results 1 to 4 of 4

Argument ByRef in a Function when not using the return value.

  1. #1
    Registered User
    Join Date
    09-02-2022
    Location
    Brussels, Belgium
    MS-Off Ver
    2016
    Posts
    2

    Argument ByRef in a Function when not using the return value.

    I have noticed an oddity when passing argument ByRef in a function when not using the return value. Take this example:


    Please Login or Register  to view this content.
    It print 15, as expected. Now remove the assignement when calling Triple:

    Please Login or Register  to view this content.
    To my surprise, it prints 5. Why this behavior? Is it documented somewhere? (I am on Excel 2016).
    Last edited by Ovier; 09-02-2022 at 04:26 AM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,457

    Re: Argument ByRef in a Function when not using the return value.

    Why would it be anything else? You have commented out the call to the function so it has not changed.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    09-02-2022
    Location
    Brussels, Belgium
    MS-Off Ver
    2016
    Posts
    2

    Re: Argument ByRef in a Function when not using the return value.

    Sorry, I wrote too fast. The unexpected behavior happens when I do call the function, but not using the return value. I have corrected the initial post.

  4. #4
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: Argument ByRef in a Function when not using the return value.

    Because you put brackets round the argument. You only use those if you are using the return value (or you use the Call statement, or are specifically trying to evaluate an expression). So use:

    Please Login or Register  to view this content.
    not:

    Please Login or Register  to view this content.
    Rory

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. byref argument type mismatch error in function
    By Aphis in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-29-2015, 05:46 AM
  2. [SOLVED] Function ByRef Argument Error
    By cocacrave in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-25-2015, 06:39 AM
  3. ByRef argument type mismatch - problem wint function
    By kmeld in forum Excel Programming / VBA / Macros
    Replies: 38
    Last Post: 12-30-2013, 09:53 AM
  4. Not able to execute a function - ByRef argument type mismatch
    By dax2ib in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-22-2013, 01:56 AM
  5. [SOLVED] ByRef argument type mismatch
    By Lloyd Blankfein in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-06-2012, 07:26 AM
  6. [SOLVED] ByRef argument type mismatch / Passing array as a function argument
    By pzling in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-29-2012, 06:23 PM
  7. Byref argument type mismatch
    By ref in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-16-2012, 06:17 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1