
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