Using := to assign a value

L

Lesley

I can't find documentation on using := to assign a value to a string variable. All the examples in manuals that I find use = instead. I'm working on somebody else's macro code

What's the meaning of := (I learned it in Pascal as "is assigned" long ago) in VBA? Why could I conceivably use both ":=" and "="

Thanks, Lesley Regan
 
J

Jay Freedman

Hi, Lesley,

In VBA, the := operator is used only to assign a value to a named parameter
in a subroutine/function call. The = operator is used everywhere else.

For example, if you declare a subroutine
Sub MySub(strIncoming As String, nLen As Integer)
...
End Sub

you could call it from another routine as
MySub strIncoming:="hello", nLen:=5

This is also used for methods of built-in objects when they take parameters,
for example
ActiveDocument.PrintOut Background:=False
 
L

Lesley

Hi, Jay

Thanks for elucidating the usage. I appreciate your promptness, also

Regards

Lesley
----- Jay Freedman wrote: ----

Hi, Lesley

In VBA, the := operator is used only to assign a value to a named paramete
in a subroutine/function call. The = operator is used everywhere else

For example, if you declare a subroutin
Sub MySub(strIncoming As String, nLen As Integer
..
End Su

you could call it from another routine a
MySub strIncoming:="hello", nLen:=

This is also used for methods of built-in objects when they take parameters
for exampl
ActiveDocument.PrintOut Background:=Fals

--
Regards
Jay Freedma
Microsoft Word MVP FAQ: http://word.mvps.or

Lesley wrote
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top