VBA: ByRef not returning changes to passed arguments

Giganews Newsgroups
Subject: VBA: ByRef not returning changes to passed arguments
Posted by:  Clif McIrvin (clare.moe@nevergmail.com.invalid)
Date: Mon, 16 Mar 2009

Small question:

Excel macro:

public myfunction(byref data as variant) as boolean
        do some stuff that modifies data
        myfunction=true
end function

sub mycode()
        dim xx as variant, x as variant
        xx = some value
05    myfunction (xx)
10    stop
15  x = myfunction(xx)
20    stop
end sub

In the locals window at line 10, xx still contains some value but at
line 20 xx has been changed.

I've done some digging through the installed documentation (Office 2003)
and see nothing that explains why.  Can someone point me towards
relevant documentation?

It seems that I first tried

05    myfunction xx

but the compiler didn't like that - it returned "argument not optional."

After changing to the line 15 syntax my macro is doing what I want, and
I'm a happy camper; just curious.

--
Clif

Replies