Can someone tell me what the deal is with this format
(just pretend no wraps):

.Paragraphs(2).Range.InlineShapes.AddPicture
FileName:=strImageName, LinkToFile:=False,
SaveWithDocument:=True
(which I have never before encountered - is it really a
method call? does it actually return a value?)

as opposed to this format:

Dim thisShape As InlineShape
Set thisShape = .Paragraphs
(2).Range.InlineShapes.AddPicture(strImageName, False,
True)

Vera

Re: VB Code formats by Jezebel

Jezebel
Wed Jan 07 13:04:08 CST 2004

The two formats do the same thing. There are two differences.

1) The first uses named arguments, the second doesn't. This is a matter of
programming preference; but using named arguments is generally considered
good practice. It's more readable, and usually you need include only the
arguments relevant to the task in hand. If you don't include the argument
names you have to get the positions right, which can be tricky if there are
many arguments. There are some (old) VB functions that do not support named
arguments.

2) The second version retrieves the reference to the added picture. This is
a programming choice. The function itself adds the picture to the document
and returns a reference to it. If you just want to add the picture then the
first version is fine; if you want to add the picture and then, in code, do
something with it, use the second.


"sestyd@yahoo.com" <anonymous@discussions.microsoft.com> wrote in message
news:008f01c3d54e$e51db2c0$a501280a@phx.gbl...
> Can someone tell me what the deal is with this format
> (just pretend no wraps):
>
> .Paragraphs(2).Range.InlineShapes.AddPicture
> FileName:=strImageName, LinkToFile:=False,
> SaveWithDocument:=True
> (which I have never before encountered - is it really a
> method call? does it actually return a value?)
>
> as opposed to this format:
>
> Dim thisShape As InlineShape
> Set thisShape = .Paragraphs
> (2).Range.InlineShapes.AddPicture(strImageName, False,
> True)
>
> Vera
>
>
>
>



Re: VB Code formats by Perry

Perry
Wed Jan 07 13:05:59 CST 2004

Not using the parameter names, you'll have to stick to
the sequence in which the parameters are passed to
a function/routine.

for starters:
AddPicture expects 3 parameters in a particular sequence.

If you want to set the 'SaveWithDocument' parameter to True

following code will work
<> .InlineShapes.AddPicture(strImageName, , True)

Following line will not set the 'SaveWithDocument' param to True
Instead, it will set LinkToFile to True:
Y're passing 2 parameters and without the reference/name, the value is
passed to
second parameter in sequence, namely: LinkToFile (and not to:
SaveWithDocument)
<> .InlineShapes.AddPicture(strImageName, True)

Following line does set the 'SaveWithDocument' param to True
despite of the fact that y're passing only 2 parameters
<> .InlineShapes.AddPicture(FileName:=strImageName, SaveWithDocument:=True)

Note: you can only skip parameters from being passed, if they're optional !!

Krgrds,
Perry

"sestyd@yahoo.com" <anonymous@discussions.microsoft.com> wrote in message
news:008f01c3d54e$e51db2c0$a501280a@phx.gbl...
> Can someone tell me what the deal is with this format
> (just pretend no wraps):
>
> .Paragraphs(2).Range.InlineShapes.AddPicture
> FileName:=strImageName, LinkToFile:=False,
> SaveWithDocument:=True
> (which I have never before encountered - is it really a
> method call? does it actually return a value?)
>
> as opposed to this format:
>
> Dim thisShape As InlineShape
> Set thisShape = .Paragraphs
> (2).Range.InlineShapes.AddPicture(strImageName, False,
> True)
>
> Vera
>
>
>
>



Re: VB Code formats by vera

vera
Wed Jan 07 14:37:19 CST 2004

Jezebel,

Thanks! That was helpful. Probably using the named
arguments will optimize the code somewhat. I guess I'm
very used to getting the positions right, I've never used
the named arguments format ever, and I've been programming
a long time!

Vera


>-----Original Message-----
>The two formats do the same thing. There are two
differences.
>
>1) The first uses named arguments, the second doesn't.
This is a matter of
>programming preference; but using named arguments is
generally considered
>good practice. It's more readable, and usually you need
include only the
>arguments relevant to the task in hand. If you don't
include the argument
>names you have to get the positions right, which can be
tricky if there are
>many arguments. There are some (old) VB functions that do
not support named
>arguments.
>
>2) The second version retrieves the reference to the
added picture. This is
>a programming choice. The function itself adds the
picture to the document
>and returns a reference to it. If you just want to add
the picture then the
>first version is fine; if you want to add the picture and
then, in code, do
>something with it, use the second.
>
>
>"sestyd@yahoo.com" <anonymous@discussions.microsoft.com>
wrote in message
>news:008f01c3d54e$e51db2c0$a501280a@phx.gbl...
>> Can someone tell me what the deal is with this format
>> (just pretend no wraps):
>>
>> .Paragraphs(2).Range.InlineShapes.AddPicture
>> FileName:=strImageName, LinkToFile:=False,
>> SaveWithDocument:=True
>> (which I have never before encountered - is it really a
>> method call? does it actually return a value?)
>>
>> as opposed to this format:
>>
>> Dim thisShape As InlineShape
>> Set thisShape = .Paragraphs
>> (2).Range.InlineShapes.AddPicture(strImageName, False,
>> True)
>>
>> Vera
>>
>>
>>
>>
>
>
>.
>