Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Newbie question (:=)

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

Thanks..


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Newbie question (:=)

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..

  #3   Report Post  
Posted to microsoft.public.excel.programming
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..



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 449
Default Newbie question (:=)

Nice one Chip. Save as HTML.

Best wishes Harald
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 225
Default Newbie question (:=)

Another benefit is when a Sub or Function has some
optional parameters. To modify Chip's example

Sub AAA(Optional A As Integer = 0, Optional B As Integer = 0, _
Optional C As Integer = 0, Optional D As Integer = 0)
' code
End Sub

Then you can write
AAAA A:=1, D:=42

rather than
AAAA 1, , , 42

and be sure you're using the right parameters and haven't
miscounted the commas.


On 6 Jan, 16:16, "Bruce A. Julseth"
wrote:
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..


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie Question Terri[_2_] New Users to Excel 8 February 23rd 08 12:21 AM
Newbie question Ekaterina Charts and Charting in Excel 2 January 30th 07 06:59 PM
Real Newbie newbie question Dave New Users to Excel 0 January 10th 07 07:55 PM
Newbie Question - Subtraction Formula Question [email protected] Excel Discussion (Misc queries) 3 May 5th 06 05:50 PM
newbie question vapor77 New Users to Excel 5 February 4th 06 12:08 AM


All times are GMT +1. The time now is 03:47 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"