Prev: Graphic Draw Question
Next: Redirection
From: Bob Butler on 2 Mar 2010 15:44 "MM" <kylix_is(a)yahoo.co.uk> wrote in message news:1ntqo51hoeruepvockkk3hqdt52vmhtbet(a)4ax.com... > On Tue, 2 Mar 2010 12:51:08 -0500, "Rick Rothstein" > <rick.newsNO.SPAM(a)NO.SPAMverizon.net> wrote: > >>> Suppose I have: >>> >>> Sub AnyProc (cbo as ComboBox) >>> MsgBox cbo.Name >>> End Sub >>> >>> With Combo1 >>> AnyProc ? >>> End With >>> >>> How can I refer to the object itself to pass to AnyProc? What I need >>> is a .Self property! >> >>Interesting question. You could, of course, just use Combo1 since you know >>it is Combo1; however, a general approach (assuming the With statement was >>using an object variable as opposed to a hard-coded control name) might be >>this... >> >>AnyProc Controls(.Name) > > Ah, I tried everything else, but not that! > > Don't you think a ".Self" property would have been useful? Like Me. If it's your own object you can add that Public Property Get Self() As whatever Set Self = Me End Property For controls you can use Rick's suggestion; for other objects you may be out of luck and have to repeat the reference explicitly With someobject .prop=42 AnyProc someobject End With
From: Karl E. Peterson on 2 Mar 2010 15:45 MM wrote: >> AnyProc Controls(.Name) > > Ah, I tried everything else, but not that! Will that work with a control array member? > Don't you think a ".Self" property would have been useful? Like Me. I think This would have been a good way to refer to whatever With is refering to. That way, it's not an extension of the object itself. -- ..NET: It's About Trust! http://vfred.mvps.org
From: Helmut Meukel on 2 Mar 2010 15:46 "MM" <kylix_is(a)yahoo.co.uk> schrieb im Newsbeitrag news:h9iqo5pens21lrjljqfqpjgfi8at2p3ad2(a)4ax.com... > Suppose I have: > > Sub AnyProc (cbo as ComboBox) > MsgBox cbo.Name > End Sub > > With Combo1 > AnyProc ? > End With > > How can I refer to the object itself to pass to AnyProc? What I need > is a .Self property! > > MM Hmm, I think it can be done. I wouldn't do this in my own code, but... How about: Sub AnyProc (ctl as Control) MsgBox ctl.Name End Sub With Combo1 .SetFocus AnyProc me.ActiveControl End With I would rather write the control's name in my code, but the above will do the trick. However setting the focus to another control might irritate the user, so you would have to write even more code to avoid this irritation: Dim oldActControl as Control With Combo1 Set oldActControl = me.ActiveControl .SetFocus AnyProc me.ActiveControl oldActControl.SetFocus Set oldActControl = Nothing End With If AnyProc is in the form code, you can reference me.ActiveControl in AnyProc without passing it as a parameter. If you are certain Combo1 has already the focus, then you don't need all I mentioned above and could simply use me.ActiveControl in AnyProc. HTH. Helmut.
From: Nobody on 2 Mar 2010 15:48 "MM" <kylix_is(a)yahoo.co.uk> wrote in message news:1ntqo51hoeruepvockkk3hqdt52vmhtbet(a)4ax.com... > Ah, I tried everything else, but not that! > > Don't you think a ".Self" property would have been useful? Like Me. Man, that would be too much OOP! :-) Personally I don't use With, it makes it harder to find variables such as "MyUDT.var1".
From: MM on 2 Mar 2010 19:00
On Tue, 2 Mar 2010 12:44:06 -0800, "Bob Butler" <noway(a)nospam.ever> wrote: > >"MM" <kylix_is(a)yahoo.co.uk> wrote in message >news:1ntqo51hoeruepvockkk3hqdt52vmhtbet(a)4ax.com... >> On Tue, 2 Mar 2010 12:51:08 -0500, "Rick Rothstein" >> <rick.newsNO.SPAM(a)NO.SPAMverizon.net> wrote: >> >>>> Suppose I have: >>>> >>>> Sub AnyProc (cbo as ComboBox) >>>> MsgBox cbo.Name >>>> End Sub >>>> >>>> With Combo1 >>>> AnyProc ? >>>> End With >>>> >>>> How can I refer to the object itself to pass to AnyProc? What I need >>>> is a .Self property! >>> >>>Interesting question. You could, of course, just use Combo1 since you know >>>it is Combo1; however, a general approach (assuming the With statement was >>>using an object variable as opposed to a hard-coded control name) might be >>>this... >>> >>>AnyProc Controls(.Name) >> >> Ah, I tried everything else, but not that! >> >> Don't you think a ".Self" property would have been useful? Like Me. > >If it's your own object you can add that > >Public Property Get Self() As whatever >Set Self = Me >End Property > >For controls you can use Rick's suggestion; for other objects you may be out >of luck and have to repeat the reference explicitly > >With someobject > .prop=42 > AnyProc someobject >End With Yeah, but that's exactly what I wanted to avoid, as it looks so messy. (Not your fault! ;) I thought VB might be man enough to accept just the dot, e.g. AnyProc . but it complained bitterly. MM |