From: Ralph on

"Peter T" <peter_t(a)discussions> wrote in message
news:ewGI$UPbKHA.5796(a)TK2MSFTNGP06.phx.gbl...
> "Nobody" <nobody(a)nobody.com> wrote in message news:%
> > "Peter T" <peter_t(a)discussions> wrote in message
> >> "Martin Trump" <martin(a)wmeadow.demon.co.uk> wrote in message
> >>
> >>>> 3 - You need to use "Set" with any object assignment, so use "Set
> >>>> pic2.Picture = Clipboard.GetData()".
> >>>
> >>> Really? pic2.Picture = Clipboard.GetData() seems to work for me.
> >>
> >> Yes both w/out Set work for me, in VBA too. I've never quite understood
> >> why.
> >
> > Looking at Object Browser(F2), the default property for both is
"Handle".
> > So that line is equivalent to:
> >
> > pic2.Picture.Handle = Clipboard.GetData().Handle
>
> AhHa, similar in VBA
> MSForms.Image.Picture - Property Picture As StdPicture
> StdPicture.Handle As OLE_HANDLE
> Default member of stdole.StdPicture
>
> Intuitively I guess .Handle = .Handle is a tad more efficient. Or is it,
any
> reason to use or not use Set?
>

Which is "more efficient" has no impact since the decision of which contruct
to use has already made behind the scenes by the VB (or VBA) Editor/Parser
when the code is first typed or read into the parser. ie, the "dye has been
cast" before the code itself ever runs.

The question is whether or not one intends to assign or re-assign an object
reference or modify the attribute of an existing object. A poor choice only
manifests itself later if the resultant object is not what the programmer
intended.

As an aside, the VB Clipboard Object is a wrapper for the system Clipboard
which itself constructs an OLE Object of the particular type to return data.
(Or reuses an existing object to honor subsequent calls.) ie, the Clipboard
Object is a far busier and more complex critter than its simple interface
might imply. <g>

-ralph


From: Peter T on
"Ralph" <nt_consulting64(a)yahoo.com> wrote in message
> "Peter T" <peter_t(a)discussions> wrote in message
>> "Nobody" <nobody(a)nobody.com> wrote in message
>> > "Peter T" <peter_t(a)discussions> wrote in message
>> >> "Martin Trump" <martin(a)wmeadow.demon.co.uk> wrote in message
>> >>
>> >>>> 3 - You need to use "Set" with any object assignment, so use "Set
>> >>>> pic2.Picture = Clipboard.GetData()".
>> >>>
>> >>> Really? pic2.Picture = Clipboard.GetData() seems to work for me.
>> >>
>> >> Yes both w/out Set work for me, in VBA too. I've never quite
>> >> understood
>> >> why.
>> >
>> > Looking at Object Browser(F2), the default property for both is
> "Handle".
>> > So that line is equivalent to:
>> >
>> > pic2.Picture.Handle = Clipboard.GetData().Handle
>>
>> AhHa, similar in VBA
>> MSForms.Image.Picture - Property Picture As StdPicture
>> StdPicture.Handle As OLE_HANDLE
>> Default member of stdole.StdPicture
>>
>> Intuitively I guess .Handle = .Handle is a tad more efficient. Or is it,
> any
>> reason to use or not use Set?
>>
>
> Which is "more efficient" has no impact since the decision of which
> contruct
> to use has already made behind the scenes by the VB (or VBA) Editor/Parser
> when the code is first typed or read into the parser. ie, the "dye has
> been
> cast" before the code itself ever runs.

OK "more efficient" was a poorly worded, but still not quite following.

> The question is whether or not one intends to assign or re-assign an
> object
> reference or modify the attribute of an existing object.

Say the intention is to assign the object (picture) to the control for
viewing, after which the object is not required for any other purpose.
Perhaps as in Martin's example -
(Set) pic2.Picture = Clipboard.GetData()

Or, if making a bmp (stdPicture) for viewing in the control

(Set) pic2.Picture = myStdPictureObject

Or, copy the picture from one control to another
(Set) pic2.Picture = pic1.Picture

To Set or not to Set or no difference?

> A poor choice only manifests itself later if the
> resultant object is not what the programmer intended

How might a poor choice of use of Set of manifest itself?

Regards,
Peter T


From: Martin Trump on

>>> 3 - You need to use "Set" with any object assignment, so use "Set
>>> pic2.Picture = Clipboard.GetData()".
>> Really? pic2.Picture = Clipboard.GetData() seems to work for me.
>
> Yes both w/out Set work for me, in VBA too. I've never quite understood why.

All this is getting too complicated for me. For amusement only may I
claim to have the smallest VB project ever posted, one line of
executable code?

In VB a project put a button and a PictureBox on Form1. The _only_ code
is :-

Private Sub Command1_Click()

Picture1.Picture = Clipboard.GetData()

End Sub

Open any picture in Paint, CNTR+A, CNTR+C, run the VB and click the
button and the picture appears. KISS?
From: Dave O. on
"Ralph" <nt_consulting64(a)yahoo.com> wrote in message
news:OUJyUHRbKHA.5472(a)TK2MSFTNGP02.phx.gbl...

> As an aside, the VB Clipboard Object is a wrapper for the system Clipboard
> which itself constructs an OLE Object of the particular type to return
> data.
> (Or reuses an existing object to honor subsequent calls.) ie, the
> Clipboard
> Object is a far busier and more complex critter than its simple interface
> might imply. <g>
>
> -ralph

Hi

I posted a comment about that on 23 Nov '09 @ 10:05 but my Outlook Express
seems to be unable to resolve the comp.lang.basic.visual.misc newsgroup,
someone might want to re-post what I said to that group.

Regards
Dave O.


From: Bob Butler on

"Nobody" <nobody(a)nobody.com> wrote in message
news:%237HScHPbKHA.5576(a)TK2MSFTNGP02.phx.gbl...
> "Peter T" <peter_t(a)discussions> wrote in message
> news:%23V0DEoObKHA.4688(a)TK2MSFTNGP06.phx.gbl...
>> "Martin Trump" <martin(a)wmeadow.demon.co.uk> wrote in message
>>
>>>> 3 - You need to use "Set" with any object assignment, so use "Set
>>>> pic2.Picture = Clipboard.GetData()".
>>>
>>> Really? pic2.Picture = Clipboard.GetData() seems to work for me.
>>
>> Yes both w/out Set work for me, in VBA too. I've never quite understood
>> why.
>
> Looking at Object Browser(F2), the default property for both is "Handle".
> So that line is equivalent to:
>
> pic2.Picture.Handle = Clipboard.GetData().Handle

That may explain that one but the same thing occurs other places (e.g. the
ADODB.CommandObject's ActiveConnection property). You can even create it
using VB.

Class1:
=======
Private moX As Object

Public Property Let MyProp(ByVal x As Object)
Set moX = x
End Property

Public Property Set MyProp(ByVal x As Object)
Set moX = x
End Property

Public Property Get MyProp() As Object
Set MyProp = moX
End Property

========
Module1:
========
Private Sub Main()
Dim c As Class1
Set c = New Class1
c.MyProp = Clipboard
MsgBox TypeName(c.MyProp)
c.MyProp = Nothing
End Sub

Since the Property Let actually uses Set the calling code can use or not use
Set and the result will be the same