View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Bruce A. Julseth[_2_] Bruce A. Julseth[_2_] is offline
external usenet poster
 
Posts: 29
Default Newbie question (:=)

Thank you very much. Excellent explanation...I'm surprised my Excel book
didn't have anything like this. At least, I couldn't find anything.

Thanks again

Bruce

"Chip Pearson" wrote in message
...
The := is used for named arguments in procedure calls. For example,
say you have a procedure like

Sub AAA (A As Integer, B As Integer, C As Integer, D As Integer)
' code
End Sub

Then, you want to call this procedure. You would normally use code
like

AAA 123, 345, 567, 678

In this line of code, it isn't readily clear what the number signify.
However, you can use named arguments to document the function call:

AAA A:=123, B:=345, C:=567, D:=678

This makes the code self-documenting, especially when the parameters
have names more descriptive than A, B, and C.

Also, with named arguments, you need not pass them in the order in
which they are declared in the called procedure. For example,

AAA D:=678, A:=123, C:=567, B:=345

is a perfectly valid function call even though the order of arguments
is D, A, C, B. The names cause the compiler to assign them correctly.

There is no reason to pass arguments out of order, and I would
recommend that you not do this, but it is possible.

In a function call, you can mix named arguments with unnamed
arguments. E.g.,

AAA 123, 345, C:=567, D:=678

However, all arguments after the first named argument must also be
named. E.g.,

AAA 123, 345, C:=567, 678

is invalid because C is named and D, which follows it, is not named.

All of the function calls to AAA are functionally equivalent. The
behave identically.


Cordially,
Chip Pearson
Microsoft MVP 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
[email on web site]




On Tue, 5 Jan 2010 21:30:43 -0500, "Bruce A. Julseth"
wrote:

When do I use :=? I googled it didn't come up with anything.

Thanks..