Newbie: what is operator COLON + EQUALS? 
Author Message
 Newbie: what is operator COLON + EQUALS?

Folks,
I keep encountering in Help & in text books the use of the operator   :=
(colon followed by equals sign)
which is not defined in any of the said text books, as far as I can see.
It seems to relate to collections and is different from the plain old equals
assignment operator.

Example under Help entry :"collections, described"

MyClasses.Add item := Inst, key := CStr(Num)

Tom S



Sat, 03 Apr 2004 00:02:10 GMT  
 Newbie: what is operator COLON + EQUALS?
This is a way of explicitly providing parameters. i.e.

MsgBox Prompt:="Do you have a problem with that?", Buttons:=vbYesNo ,
Title:="Sample Message Box"

This could also be written as:
MsgBox Buttons:=vbYesNo , Title:="Sample Message Box", Prompt:="Do you have
a problem with that?"

The alternative is implicit provision which uses the position rather than
the name of the parameter.

MsgBox "Do you have a problem with that?", vbYesNo, "Sample Message Box"

In this example, if you change the order, you change the meaning.

Hope this helps,
--
Charles Kenyon

Word New User FAQ & Web Directory:
<URL: http://www.addbalance.com/word/index.htm>

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide)
<URL: http://www.addbalance.com/usersguide/index.htm>

See also the MVP FAQ: <URL: http://www.mvps.org/word/> which is awesome!
 --------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.


Quote:
> Folks,
> I keep encountering in Help & in text books the use of the operator   :=
> (colon followed by equals sign)
> which is not defined in any of the said text books, as far as I can see.
> It seems to relate to collections and is different from the plain old
equals
> assignment operator.

> Example under Help entry :"collections, described"

> MyClasses.Add item := Inst, key := CStr(Num)

> Tom S



Sat, 03 Apr 2004 00:17:49 GMT  
 Newbie: what is operator COLON + EQUALS?
Hi, Tom,

The := is used only to assign named parameter values in a procedure call.
Now for an explanation of that bit of geekspeak:

A "procedure call" can be a reference to an object's method, a call to a
built-in statement or function (like MsgBox), or a call to a Sub or Function
that you write yourself.

If the procedure has a list of parameters that form its input, you have a
choice of whether to supply the parameter values "by position" or "by name".
For example, the Help shows that MsgBox takes parameters of Prompt, Buttons,
Title, and so forth, and all of them except Prompt are optional. Let's say
you want to provide values for Prompt and Title, but not for Buttons or the
others. You could supply the parameters by position with

   MsgBox "My prompt", , "My Title"

where the empty comma is a placeholder for the Buttons parameter, or you
could supply them by name with

   MsgBox Prompt:="My prompt", Title:="My Title"

and not have to worry about whether you got the positions right. Also, when
you use named parameters, you don't have to place them in the same order as
shown by the Help (although that may make the code a bit confusing to read).

Instead of the constants I showed, you can use a variable of the correct
type, or an expression involving variables and constants, on the right side
of the := operator. On the left side, you must use the parameter name shown
in the Help (or in the "IntelliSense" popup that appears while you're typing
the code).

In all other instances where you assign values or compare values in VB,
don't use the colon. (No, I don't know why VB was designed this way.)

--
Regards,
Jay Freedman
Microsoft Word MVP        Word MVP FAQ site: http://www.mvps.org/word


Quote:
> Folks,
> I keep encountering in Help & in text books the use of the operator   :=
> (colon followed by equals sign)
> which is not defined in any of the said text books, as far as I can see.
> It seems to relate to collections and is different from the plain old
equals
> assignment operator.

> Example under Help entry :"collections, described"

> MyClasses.Add item := Inst, key := CStr(Num)

> Tom S



Sat, 03 Apr 2004 00:33:38 GMT  
 Newbie: what is operator COLON + EQUALS?
It is the assignment operator, and is used to assign references to
function or procedure arguments. For instance,

MyClasses.Add item:= Inst, key:= CStr(Num)

assigns the reference to Inst to the item argument of the Add Method of
MyClasses.

it is different than an = sign in that no values/references are changed
(as for example in the statmement myval = 2  - the value of myval is
actually changed to 2).

Help is very bad at defining this operator - it does so in several
places, but only by highlighting the difference in passing arguments by
position or by name.


Quote:

> Folks,
> I keep encountering in Help & in text books the use of the operator   :=
> (colon followed by equals sign)
> which is not defined in any of the said text books, as far as I can see.
> It seems to relate to collections and is different from the plain old equals
> assignment operator.

> Example under Help entry :"collections, described"

> MyClasses.Add item := Inst, key := CStr(Num)

> Tom S

--

ROT13 encoding, decode for real mail


Sat, 03 Apr 2004 00:34:57 GMT  
 Newbie: what is operator COLON + EQUALS?

It's not an operator per se, and it's not specific to collections.  
It's what links a parameter name with its value.  Parameter names
are usually optional, but are often helpful if you're giving only
a few of many available parameters.  

For example, the PrintOut method of ActiveDocument object, has over
a dozen parameters.  The 'Copies' parameter is the 8th one.  If the
only parameter you needed to set was the number of copies (say, 3),
you could use:

   ActiveDocument.PrintOut , , , , , , , 3

painstakingly counting the commas to be sure you were placing the
'3' in the correct spot.  Or you could specify the parameter name
and not have to place it in sequence:

   ActiveDocument.PrintOut Copies:=3

When using parameter names the *order* of the parameters also doesn't
matter.  The following 2 statements do the same thing:

   ActiveDocument.PrintOut Copies:=3, Pages:=10
   ActiveDocument.PrintOut Pages:=10, Copies:=3

But without parameter names you'd have to write this:

   ActiveDocument.PrintOut , , , , , , , 3, 10

Hope this helps a little.


-- See the MVP FAQ at http://www.mvps.org/word ----------------------
------------- "Life is nothing if you're not obsessed." --John Waters
---------------------------------------------------------------------
Please reply only to the newsgroup.

Quote:

> Folks,
> I keep encountering in Help & in text books the use of the operator   :=
> (colon followed by equals sign)
> which is not defined in any of the said text books, as far as I can see.
> It seems to relate to collections and is different from the plain old equals
> assignment operator.

> Example under Help entry :"collections, described"

> MyClasses.Add item := Inst, key := CStr(Num)

> Tom S



Sat, 03 Apr 2004 07:18:22 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. colon equal ?

2. Equality '=' operator and Object.equals()

3. newbie question: pointers and bitwise operators and OCX file

4. String comparison using Or logical operator - newbie

5. I am Newbie , Please Help

6. EASY QUESTION but i am a newbie

7. Help Me please, I am a newbie

8. Today I am a newbie

9. Help Please! I am a Newbie :P

10. I am a VB newbie, looking for good manual

11. Newbie: What am I doing wrong?

12. i am a newbie who needs help.

 

 
Powered by phpBB® Forum Software